{
boolean authenticated = false;
InternalUserPrincipal internalUser = securityAccess.getInternalUserPrincipal(userName, false);
if (null != internalUser)
{
InternalCredential credential = getPasswordCredential(internalUser, userName );
if ( credential != null && credential.isEnabled() && !credential.isExpired())
{
String encodedPassword = password;
if ( pcProvider.getEncoder() != null && credential.isEncoded())
{
if ( pcProvider.getEncoder() instanceof AlgorithmUpgradeCredentialPasswordEncoder )
{
encodedPassword = ((AlgorithmUpgradeCredentialPasswordEncoder)pcProvider.getEncoder()).encode(userName,password, credential);
}
else
{
encodedPassword = pcProvider.getEncoder().encode(userName,password);
}
}
authenticated = credential.getValue().equals(encodedPassword);
boolean update = false;
if ( ipcInterceptor != null )
{
update = ipcInterceptor.afterAuthenticated(internalUser, userName, credential, authenticated);
if ( update && (!credential.isEnabled() || credential.isExpired()))
{
authenticated = false;
}
}
long time = new Date().getTime();
if ( authenticated )
{
credential.setAuthenticationFailures(0);
if ( pcProvider.getEncoder() != null && pcProvider.getEncoder() instanceof AlgorithmUpgradeCredentialPasswordEncoder)
{
((AlgorithmUpgradeCredentialPasswordEncoder)pcProvider.getEncoder()).recodeIfNeeded(userName,password,credential);
}
credential.setPreviousAuthenticationDate(credential.getLastAuthenticationDate());
credential.setLastAuthenticationDate(new Timestamp(time));
update = true;
}
if ( update )
{
credential.setModifiedDate(new Timestamp(time));
internalUser.setModifiedDate(new Timestamp(time));
securityAccess.setInternalUserPrincipal(internalUser, false);
}
}
}