Ejemplo n.º 1
0
  private void convertDeprecatedPropertyNames() {
    Enumeration<?> keys = userDataProp.propertyNames();

    boolean doSave = false;

    while (keys.hasMoreElements()) {
      String key = (String) keys.nextElement();

      if (key.startsWith(DEPRECATED_PREFIX)) {
        String newKey = PREFIX + key.substring(DEPRECATED_PREFIX.length());
        userDataProp.setProperty(newKey, userDataProp.getProperty(key));
        userDataProp.remove(key);

        doSave = true;
      }
    }

    if (doSave) {
      try {
        saveUserData();
      } catch (FtpException e) {
        throw new FtpServerConfigurationException("Failed to save updated user data", e);
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Delete an user. Removes all this user entries from the properties. After removing the
   * corresponding from the properties, save the data.
   */
  public synchronized void delete(String usrName) throws FtpException {
    lazyInit();

    // remove entries from properties
    String thisPrefix = PREFIX + usrName + '.';
    Enumeration<?> propNames = userDataProp.propertyNames();
    ArrayList<String> remKeys = new ArrayList<String>();
    while (propNames.hasMoreElements()) {
      String thisKey = propNames.nextElement().toString();
      if (thisKey.startsWith(thisPrefix)) {
        remKeys.add(thisKey);
      }
    }
    Iterator<String> remKeysIt = remKeys.iterator();
    while (remKeysIt.hasNext()) {
      userDataProp.remove(remKeysIt.next());
    }

    saveUserData();
  }
Ejemplo n.º 3
0
  /** Get all user names. */
  public synchronized String[] getAllUserNames() {
    lazyInit();

    // get all user names
    String suffix = '.' + ATTR_HOME;
    ArrayList<String> ulst = new ArrayList<String>();
    Enumeration<?> allKeys = userDataProp.propertyNames();
    int prefixlen = PREFIX.length();
    int suffixlen = suffix.length();
    while (allKeys.hasMoreElements()) {
      String key = (String) allKeys.nextElement();
      if (key.endsWith(suffix)) {
        String name = key.substring(prefixlen);
        int endIndex = name.length() - suffixlen;
        name = name.substring(0, endIndex);
        ulst.add(name);
      }
    }

    Collections.sort(ulst);
    return ulst.toArray(new String[0]);
  }