Ejemplo n.º 1
0
  /** Save user data. Store the properties. */
  public synchronized void save(User usr) throws FtpException {
    lazyInit();

    // null value check
    if (usr.getName() == null) {
      throw new NullPointerException("User name is null.");
    }
    String thisPrefix = PREFIX + usr.getName() + '.';

    // set other properties
    userDataProp.setProperty(thisPrefix + ATTR_PASSWORD, getPassword(usr));

    String home = usr.getHomeDirectory();
    if (home == null) {
      home = "/";
    }
    userDataProp.setProperty(thisPrefix + ATTR_HOME, home);
    userDataProp.setProperty(thisPrefix + ATTR_ENABLE, usr.getEnabled());
    userDataProp.setProperty(
        thisPrefix + ATTR_WRITE_PERM, usr.authorize(new WriteRequest()) != null);
    userDataProp.setProperty(thisPrefix + ATTR_MAX_IDLE_TIME, usr.getMaxIdleTime());

    TransferRateRequest transferRateRequest = new TransferRateRequest();
    transferRateRequest = (TransferRateRequest) usr.authorize(transferRateRequest);

    if (transferRateRequest != null) {
      userDataProp.setProperty(
          thisPrefix + ATTR_MAX_UPLOAD_RATE, transferRateRequest.getMaxUploadRate());
      userDataProp.setProperty(
          thisPrefix + ATTR_MAX_DOWNLOAD_RATE, transferRateRequest.getMaxDownloadRate());
    } else {
      userDataProp.remove(thisPrefix + ATTR_MAX_UPLOAD_RATE);
      userDataProp.remove(thisPrefix + ATTR_MAX_DOWNLOAD_RATE);
    }

    // request that always will succeed
    ConcurrentLoginRequest concurrentLoginRequest = new ConcurrentLoginRequest(0, 0);
    concurrentLoginRequest = (ConcurrentLoginRequest) usr.authorize(concurrentLoginRequest);

    if (concurrentLoginRequest != null) {
      userDataProp.setProperty(
          thisPrefix + ATTR_MAX_LOGIN_NUMBER, concurrentLoginRequest.getMaxConcurrentLogins());
      userDataProp.setProperty(
          thisPrefix + ATTR_MAX_LOGIN_PER_IP, concurrentLoginRequest.getMaxConcurrentLoginsPerIP());
    } else {
      userDataProp.remove(thisPrefix + ATTR_MAX_LOGIN_NUMBER);
      userDataProp.remove(thisPrefix + ATTR_MAX_LOGIN_PER_IP);
    }

    saveUserData();
  }
Ejemplo n.º 2
0
  /**
   * Get user password. Returns the encrypted value.
   *
   * <p>
   *
   * <pre>
   * If the password value is not null
   *    password = new password
   * else
   *   if user does exist
   *     password = old password
   *   else
   *     password = &quot;&quot;
   * </pre>
   */
  private String getPassword(User usr) {
    String name = usr.getName();
    String password = usr.getPassword();

    if (password != null) {
      password = passwordEncryptor.encrypt(password);
    } else {
      String blankPassword = passwordEncryptor.encrypt("");

      if (doesExist(name)) {
        String key = PREFIX + name + '.' + ATTR_PASSWORD;
        password = userDataProp.getProperty(key, blankPassword);
      } else {
        password = blankPassword;
      }
    }
    return password;
  }