use of org.apache.ftpserver.ftplet.AuthenticationFailedException in project structr by structr.
the class StructrUserManager method authenticate.
@Override
public User authenticate(Authentication auth) throws AuthenticationFailedException {
logger.debug("Authentication: {}", auth);
String userName = null;
String password = null;
if (auth instanceof UsernamePasswordAuthentication) {
org.structr.web.entity.User user = null;
// Use superuser context for authentication only
try (Tx tx = StructrApp.getInstance().tx()) {
UsernamePasswordAuthentication authentication = (UsernamePasswordAuthentication) auth;
userName = authentication.getUsername();
password = authentication.getPassword();
user = (org.structr.web.entity.User) AuthHelper.getPrincipalForPassword(Principal.name, userName, password);
securityContext = SecurityContext.getInstance(user, AccessMode.Backend);
tx.success();
} catch (FrameworkException ex) {
logger.warn("FTP authentication attempt failed with username {} and password {}", new Object[] { userName, password });
}
if (user != null) {
return new StructrFtpUser(securityContext, user);
}
}
throw new AuthenticationFailedException("No structr user found for credentials " + userName + "/" + password);
}
use of org.apache.ftpserver.ftplet.AuthenticationFailedException in project ddf by codice.
the class UserManagerImpl method authenticate.
/**
* @param authentication The {@link Authentication} that proves the users identity. {@link org.apache.ftpserver.usermanager.AnonymousAuthentication} is not permitted
* @return {@link User} upon successful authorization
* @throws AuthenticationFailedException upon unsuccessful authorization
*/
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
UPAuthenticationToken upAuthenticationToken;
String username;
User user;
if (authentication instanceof UsernamePasswordAuthentication) {
username = ((UsernamePasswordAuthentication) authentication).getUsername();
upAuthenticationToken = new UPAuthenticationToken(username, ((UsernamePasswordAuthentication) authentication).getPassword());
try {
Subject subject = securityManager.getSubject(upAuthenticationToken);
if (subject != null) {
if (!doesExist(username)) {
user = createUser(username, subject);
} else {
user = getUserByName(username);
updateUserSubject(user, subject);
}
return user;
}
} catch (SecurityServiceException e) {
LOGGER.info("Failure to retrieve subject.", e);
throw new AuthenticationFailedException("Failure to retrieve subject.");
}
}
throw new AuthenticationFailedException("Authentication failed");
}
Aggregations