// Extract user credentials
UsernamePasswordToken token = (UsernamePasswordToken) at;
String username = token.getUsername();
// Extract user from the database
FireUser resolvedUser;
try {
resolvedUser = userManager.findUser(username);
} catch (PersistenceException e) {
FireLogger.logSevere("Realm {0} has encountered a database problem: {1}", getName(), e.getClass());
throw new AuthenticationException("Database error: " + e.getMessage());
}
if (resolvedUser == null) {
FireLogger.logSevere("Realm {0} found no match for user {1}", getName(), username);
throw new UnknownAccountException("Unable to locate user: " + username);
}
// Extract password and check for match
Password resolvedPassword;
try {
resolvedPassword = passwordManager.findPassword(resolvedUser);
} catch (Exception e) {
FireLogger.logSevere("Realm {0} has encountered a database problem: {1}", getName(), e.getClass());
throw new AuthenticationException("Database error: " + e.getMessage());
}
// If the password does not exist, the user will have to create a new one
if (resolvedPassword == null) {
FireLogger.logSevere("Realm {0} found no matching password for user {1}", getName(), username);
throw new UnknownAccountException("Password for account could not be found. New password must be created");
}
FireLogger.logInfo("Realm {0} generated SimpleAuthenticationToken for user {1}", getName(), username);
return new SimpleAuthenticationInfo(resolvedUser.getEmail(),
resolvedPassword.getPassword(),
new SimpleByteSource(resolvedPassword.getSalt()),
getName());
}