protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
throws AuthenticationException
{
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
CUser user;
try {
user = configuration.readUser(upToken.getUsername());
}
catch (UserNotFoundException e) {
throw new AccountException("User '" + upToken.getUsername() + "' cannot be retrieved.", e);
}
if (user.getPassword() == null) {
throw new AccountException("User '" + upToken.getUsername() + "' has no password, cannot authenticate.");
}
if (CUser.STATUS_ACTIVE.equals(user.getStatus())) {
//Check for legacy user that has unsalted password hash
//Update if legacy user, and valid credentials were specified
if (this.isLegacyUser(user) && this.isValidCredentials(upToken, user)) {
this.reHashPassword(user, new String(upToken.getPassword()));
}
return this.createAuthenticationInfo(user);
}
else if (CUser.STATUS_DISABLED.equals(user.getStatus())) {
throw new DisabledAccountException("User '" + upToken.getUsername() + "' is disabled.");
}
else {
throw new AccountException("User '" + upToken.getUsername() + "' is in illegal status '"
+ user.getStatus() + "'.");
}
}