本文整理汇总了Java中org.apache.ftpserver.usermanager.UsernamePasswordAuthentication.getUsername方法的典型用法代码示例。如果您正苦于以下问题:Java UsernamePasswordAuthentication.getUsername方法的具体用法?Java UsernamePasswordAuthentication.getUsername怎么用?Java UsernamePasswordAuthentication.getUsername使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ftpserver.usermanager.UsernamePasswordAuthentication
的用法示例。
在下文中一共展示了UsernamePasswordAuthentication.getUsername方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import org.apache.ftpserver.usermanager.UsernamePasswordAuthentication; //导入方法依赖的package包/类
@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
if (authentication instanceof UsernamePasswordAuthentication) {
UsernamePasswordAuthentication usernameAndPassword = (UsernamePasswordAuthentication) authentication;
String username = usernameAndPassword.getUsername();
User user = users.get(username);
if (null == user) {
throw new AuthenticationFailedException("unknown user '" + username + "'");
}
String password = usernameAndPassword.getPassword();
if (getPasswordEncryptor().matches(password, user.getPassword())) {
return user;
} else {
throw new AuthenticationFailedException("password wrong");
}
}
throw new AuthenticationFailedException("try harder");
}
示例2: authenticate
import org.apache.ftpserver.usermanager.UsernamePasswordAuthentication; //导入方法依赖的package包/类
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
if ((authentication instanceof UsernamePasswordAuthentication) == false) {
throw new AuthenticationFailedException("Can't manage " + authentication.getClass().getSimpleName() + " auth class.");
}
UsernamePasswordAuthentication auth = (UsernamePasswordAuthentication) authentication;
String addr = auth.getUserMetadata().getInetAddress().getHostAddress();
String username = auth.getUsername();
String login_name = FTPUser.makeUserId(username, domain);
try {
FTPUser user = FTPUser.getUserByName(username, domain);
if (user == null) {
AccessControl.failedAttempt(addr, login_name);
return null;
}
if (user.validPassword(auth)) {
AccessControl.releaseIP(addr);
return user.updateLastLogin();
} else {
AccessControl.failedAttempt(addr, login_name);
}
} catch (ConnectionException e) {
Loggers.FTPserver.error("Can't access to db", e);
}
return null;
}
示例3: authenticate
import org.apache.ftpserver.usermanager.UsernamePasswordAuthentication; //导入方法依赖的package包/类
@Override
public User authenticate(final Authentication inAuth) throws AuthenticationFailedException {
UsernamePasswordAuthentication upa = (UsernamePasswordAuthentication) inAuth;
String login = upa.getUsername();
String password = upa.getPassword();
if (user.equals(login) && pass.equals(password))
return new FtpUser(homePath, login, password);
throw new AuthenticationFailedException();
}
示例4: authenticate
import org.apache.ftpserver.usermanager.UsernamePasswordAuthentication; //导入方法依赖的package包/类
/**
* User authenticate method
*/
public User authenticate(Authentication authentication)
throws AuthenticationFailedException {
if (authentication instanceof UsernamePasswordAuthentication) {
UsernamePasswordAuthentication upauth = (UsernamePasswordAuthentication) authentication;
String user = upauth.getUsername();
String password = upauth.getPassword();
if (user == null) {
throw new AuthenticationFailedException("Authentication failed");
}
if (password == null) {
password = "";
}
String storedPassword = userDataProp.getProperty(PREFIX + user
+ '.' + ATTR_PASSWORD);
if (storedPassword == null) {
// user does not exist
throw new AuthenticationFailedException("Authentication failed");
}
if (getPasswordEncryptor().matches(password, storedPassword)) {
return getUserByName(user);
} else {
throw new AuthenticationFailedException("Authentication failed");
}
} else if (authentication instanceof AnonymousAuthentication) {
if (doesExist("anonymous")) {
return getUserByName("anonymous");
} else {
throw new AuthenticationFailedException("Authentication failed");
}
} else {
throw new IllegalArgumentException(
"Authentication not supported by this user manager");
}
}