org.apache.ftpserver.usermanager.UsernamePasswordAuthentication Java Examples

The following examples show how to use org.apache.ftpserver.usermanager.UsernamePasswordAuthentication. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FtpUserManager.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
    if (authentication instanceof UsernamePasswordAuthentication) {
        if (mUsers.isEmpty())
            throw new AuthenticationFailedException("Authentication failed");
        final UsernamePasswordAuthentication auth =
                (UsernamePasswordAuthentication) authentication;
        final String username = auth.getUsername();
        final String password = auth.getPassword();
        final Collection<FtpUser> users = mUsers.values();
        for (FtpUser user : users) {
            if (username.equals(user.getName()) &&
                    TextUtils.equals(password, user.getPassword()))
                return user;
        }
        throw new AuthenticationFailedException("Authentication failed");
    } else if (authentication instanceof AnonymousAuthentication) {
        if (isAnonymousLoginEnabled()) {
            return getUserByName(FtpUser.NAME_ANONYMOUS);
        } else {
            throw new AuthenticationFailedException("Authentication failed");
        }
    }
    throw new AuthenticationFailedException("Authentication failed");
}
 
Example #2
Source File: StorageUserManager.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
	if (authentication instanceof UsernamePasswordAuthentication) {
		UsernamePasswordAuthentication upauth = (UsernamePasswordAuthentication) authentication;
		String name = upauth.getUsername();
		String password = upauth.getPassword();
		if (name == null) {
			throw new AuthenticationFailedException("Authentication failed");
		}
		if (password == null) {
			password = "";
		}
		User user;
		try {
			user = getUserByName(name);
		} catch (FtpException e) {
			throw new AuthenticationFailedException("Authentication failed");
		}
		if (null == user) {
			throw new AuthenticationFailedException("Authentication failed");
		}
		if (StringUtils.equals(user.getPassword(), password)) {
			return user;
		} else {
			throw new AuthenticationFailedException("Authentication failed");
		}
	} else if (authentication instanceof AnonymousAuthentication) {
		throw new AuthenticationFailedException("Authentication failed");
	} else {
		throw new IllegalArgumentException("Authentication not supported by this user manager");
	}
}
 
Example #3
Source File: InMemoryUserManager.java    From portable-ftp-server with GNU General Public License v3.0 5 votes vote down vote up
@Override
public User authenticate(Authentication auth) throws AuthenticationFailedException {
	if(auth!=null && auth instanceof UsernamePasswordAuthentication){
		UsernamePasswordAuthentication userAuth = (UsernamePasswordAuthentication) auth;
		if(user.getName().equals(userAuth.getUsername()) && user.getPassword().equals(userAuth.getPassword())){
			return user;
		}
	}
	return null;
}
 
Example #4
Source File: FtpUserManager.java    From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public User authenticate(Authentication authentication) {
    if (UsernamePasswordAuthentication.class.isAssignableFrom(authentication.getClass())) {
        UsernamePasswordAuthentication upAuth = (UsernamePasswordAuthentication) authentication;
        BaseUser user = users.get(upAuth.getUsername());
        if (user != null && user.getPassword().equals(upAuth.getPassword())) {
            return user;
        }
    } else if (AnonymousAuthentication.class.isAssignableFrom(authentication.getClass())) {
        return users.get("anonymous");
    }
    return null;
}