throws LoginException
{
if (username.equals(this.anonymousUser))
{
throw new LoginException("Anonymous user cannot login");
}
JetspeedUser user = null;
username = JetspeedSecurity.convertUserName(username);
password = JetspeedSecurity.convertPassword(password);
try
{
user = JetspeedUserManagement.getUser(new UserNamePrincipal(username));
password = JetspeedSecurity.encryptPassword(password);
}
catch (UnknownUserException e)
{
logger.warn("Unknown user attempted access: " + username, e);
throw new FailedLoginException(e.toString());
}
catch (JetspeedSecurityException e)
{
logger.warn("User denied authentication: " + username, e);
throw new LoginException(e.toString());
}
if(!user.getPassword().equals(password))
{
logger.error("Invalid password for user: " + username);
throw new FailedLoginException("Credential authentication failure");
}
// Check for password expiration
if (this.expirationPeriod > 0)
{
Date passwordLastChangedDate = user.getPasswordChanged();
Date passwordExpireDate = null;
if (passwordLastChangedDate != null) {
GregorianCalendar gcal = (GregorianCalendar) GregorianCalendar.getInstance();
gcal.setTime(passwordLastChangedDate);
gcal.add(GregorianCalendar.DATE, this.expirationPeriod);
passwordExpireDate = gcal.getTime();
if (logger.isDebugEnabled())
{
logger.debug("TurbineAuthentication: password last changed = " + passwordLastChangedDate.toString() +
", password expires = " + passwordExpireDate.toString());
}
}
if (passwordExpireDate == null || (new Date().getTime() > passwordExpireDate.getTime())) {
throw new CredentialExpiredException("Password expired");
}
}
// Mark the user as being logged in.
user.setHasLoggedIn(new Boolean(true));
// Set the last_login date in the database.
try
{
user.updateLastLogin();
putUserIntoContext(user);
if (cachingEnable)
{
JetspeedSecurityCache.load(username);
}
}
catch (Exception e)
{
logger.error( "Failed to update last login ", e);
putUserIntoContext(JetspeedSecurity.getAnonymousUser());
throw new LoginException("Failed to update last login ", e);
}
return user;
}