/** * Creates a {@link PropertiesUserManager} instance based on the provided configuration */ public UserManager createUserManager() { if (userDataURL != null) { return new PropertiesUserManager(passwordEncryptor, userDataURL, adminName); } else { return new PropertiesUserManager(passwordEncryptor, userDataFile, adminName); } }
/** * Reloads the contents of the user.properties file. This allows any manual modifications to the file to be recognised by the running server. */ public void refresh() { synchronized (userDataProp) { if (userDataFile != null) { LOG.debug("Refreshing user manager using file: " + userDataFile.getAbsolutePath()); loadFromFile(userDataFile); } else { //file is null, must have been created using URL LOG.debug("Refreshing user manager using URL: " + userUrl.toString()); loadFromUrl(userUrl); } } }
if (getPasswordEncryptor().matches(password, storedPassword)) { return getUserByName(user); } else { throw new AuthenticationFailedException("Authentication failed"); if (doesExist("anonymous")) { return getUserByName("anonymous"); } else { throw new AuthenticationFailedException("Authentication failed");
/** * Get user password. Returns the encrypted value. * * <pre> * If the password value is not null * password = new password * else * if user does exist * password = old password * else * password = "" * </pre> */ private String getPassword(User usr) { String name = usr.getName(); String password = usr.getPassword(); if (password != null) { password = getPasswordEncryptor().encrypt(password); } else { String blankPassword = getPasswordEncryptor().encrypt(""); if (doesExist(name)) { String key = PREFIX + name + '.' + ATTR_PASSWORD; password = userDataProp.getProperty(key, blankPassword); } else { password = blankPassword; } } return password; }
userDataProp.setProperty(thisPrefix + ATTR_PASSWORD, getPassword(usr)); saveUserData();
/** * Internal constructor, do not use directly. Use {@link PropertiesUserManagerFactory} instead. */ public PropertiesUserManager(PasswordEncryptor passwordEncryptor, File userDataFile, String adminName) { super(adminName, passwordEncryptor); loadFromFile(userDataFile); }
/** * Internal constructor, do not use directly. Use {@link PropertiesUserManagerFactory} instead. */ public PropertiesUserManager(PasswordEncryptor passwordEncryptor, URL userDataPath, String adminName) { super(adminName, passwordEncryptor); loadFromUrl(userDataPath); }
/** * Delete an user. Removes all this user entries from the properties. After * removing the corresponding from the properties, save the data. */ public void delete(String usrName) throws FtpException { // 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(); }
File file = ((PropertiesUserManager) um).getFile();
if (!doesExist(userName)) { return null;
public static void initFtpServer() throws Exception { FtpServerFactory serverFactory = new FtpServerFactory(); // setup user management to read our users.properties and use clear text passwords URL url = ObjectHelper.loadResourceAsURL("users.properties"); UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), url, "admin"); serverFactory.setUserManager(uman); NativeFileSystemFactory fsf = new NativeFileSystemFactory(); fsf.setCreateHome(true); serverFactory.setFileSystem(fsf); ListenerFactory factory = new ListenerFactory(); factory.setPort(port); serverFactory.addListener("default", factory.createListener()); ftpServer = serverFactory.createServer(); }
public static void initFtpServer() throws Exception { FtpServerFactory serverFactory = new FtpServerFactory(); // setup user management to read our users.properties and use clear text passwords URL url = ObjectHelper.loadResourceAsURL("users.properties"); UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), url, "admin"); serverFactory.setUserManager(uman); NativeFileSystemFactory fsf = new NativeFileSystemFactory(); fsf.setCreateHome(true); serverFactory.setFileSystem(fsf); ListenerFactory factory = new ListenerFactory(); factory.setPort(port); serverFactory.addListener("default", factory.createListener()); ftpServer = serverFactory.createServer(); }