if (log.isTraceEnabled()) {
log.trace(">authenticateUser(" + username + ", hiddenpwd)");
}
try {
// Find the user with username username, or throw FinderException
final UserData data = UserData.findByUsername(entityManager, username);
if (data == null) {
throw new ObjectNotFoundException("Could not find username " + username);
}
// Decrease the remaining login attempts. When zero, the status is set to STATUS_GENERATED
userAdminSession.decRemainingLoginAttempts(admin, username);
final int status = data.getStatus();
if ( (status == UserDataConstants.STATUS_NEW) || (status == UserDataConstants.STATUS_FAILED) || (status == UserDataConstants.STATUS_INPROCESS) || (status == UserDataConstants.STATUS_KEYRECOVERY)) {
if (log.isDebugEnabled()) {
log.debug("Trying to authenticate user: username="+username+", dn="+data.getSubjectDN()+", email="+data.getSubjectEmail()+", status="+status+", type="+data.getType());
}
if (!data.comparePassword(password)) {
final String msg = intres.getLocalizedMessage("authentication.invalidpwd", username);
logSession.log(admin, data.getCaId(), LogConstants.MODULE_CA, new Date(),username, null, LogConstants.EVENT_ERROR_USERAUTHENTICATION,msg);
throw new AuthLoginException(msg);
}
// Resets the remaining login attempts as this was a successful login
userAdminSession.resetRemainingLoginAttempts(admin, username);
// Log formal message that authentication was successful
final String msg = intres.getLocalizedMessage("authentication.authok", username);
logSession.log(admin, data.getCaId(), LogConstants.MODULE_CA, new Date(),username, null, LogConstants.EVENT_INFO_USERAUTHENTICATION, msg);
if (log.isTraceEnabled()) {
log.trace("<authenticateUser("+username+", hiddenpwd)");
}
return data.toUserDataVO();
}
final String msg = intres.getLocalizedMessage("authentication.wrongstatus", UserDataConstants.getStatusText(status), Integer.valueOf(status), username);
logSession.log(admin, data.getCaId(), LogConstants.MODULE_CA, new Date(),username, null, LogConstants.EVENT_INFO_USERAUTHENTICATION, msg);
throw new AuthStatusException(msg);
} catch (ObjectNotFoundException oe) {
final String msg = intres.getLocalizedMessage("authentication.usernotfound", username);
logSession.log(admin, admin.getCaId(), LogConstants.MODULE_CA, new Date(),username, null, LogConstants.EVENT_INFO_USERAUTHENTICATION, msg);
throw oe;