public User login(Map loginContext)
throws AuthenticationException {
// get user name and password
final String name = (String)loginContext.get(ApplicationManager.LOGIN_CONTEXT_USERNAME_KEY);
if ( name == null ) {
throw new AuthenticationException("Required user name property is missing for login.");
}
final String password = (String)loginContext.get(ApplicationManager.LOGIN_CONTEXT_PASSWORD_KEY);
final UserInfo userinfo = this.userDAO.getUserInfo(name);
if ( userinfo == null ) {
return null;
}
boolean pwCorrect = StringUtils.equals(userinfo.getPassword(), password);
// check retry count
if ( this.useRetryCount ) {
if ( !negateRetryCount ) {
if ( userinfo.getRetryCount() >= this.defaultRetryCount ) {
throw new AuthenticationException(AuthenticationException.AUTHENTICATION_FAILED_ACCOUNT_IS_CLOSED);
}
if ( !pwCorrect ) {
userinfo.setRetryCount(userinfo.getRetryCount() + 1);
this.userDAO.storeUserInfo(userinfo);
if ( userinfo.getRetryCount() == this.defaultRetryCount ) {
throw new AuthenticationException(AuthenticationException.AUTHENTICATION_FAILED_ACCOUNT_CLOSED);
}
} else {
// reset retry count
if ( userinfo.getRetryCount() != 0 ) {
userinfo.setRetryCount(0);
this.userDAO.storeUserInfo(userinfo);
}
}
} else {
// the account is disabled when the counter is zero!
if ( userinfo.getRetryCount() == 0 ) {
throw new AuthenticationException(AuthenticationException.AUTHENTICATION_FAILED_ACCOUNT_IS_CLOSED);
}
if ( !pwCorrect ) {
userinfo.setRetryCount(userinfo.getRetryCount() - 1);
this.userDAO.storeUserInfo(userinfo);
if ( userinfo.getRetryCount() == 0 ) {
throw new AuthenticationException(AuthenticationException.AUTHENTICATION_FAILED_ACCOUNT_CLOSED);
}
} else {
// reset retry count
if ( userinfo.getRetryCount() != this.defaultRetryCount ) {
userinfo.setRetryCount(this.defaultRetryCount);
this.userDAO.storeUserInfo(userinfo);
}
}
}
}
// check expires
if ( pwCorrect && this.checkExpires ) {
final Date now = new Date();
if ( userinfo.getExpires() != null ) {
if ( userinfo.getExpires().before(now) ) {
throw new AuthenticationException(AuthenticationException.AUTHENTICATION_FAILED_PASSWORD_EXPIRED);
}
}
}
// everything still correct?
if ( !pwCorrect ) {