if (synchronizer != null)
{
synchronizer.synchronizeUserPrincipal(userName);
}
}
PasswordCredential credential = isPersistCredentials() ? upcam.getPasswordCredential(userName) : new PasswordCredentialImpl();
if (credential == null)
{
credential = new PasswordCredentialImpl();
// persistCredentials but user credentials not yet synchronized/stored
if (um == null)
{
log.error("New User PasswordCredential cannot be persisted: requires UserManager to be set!!!");
}
else
{
// to be able to store the new password credential it needs the User to be set
((PasswordCredentialImpl)credential).setUser(um.getUser(userName));
}
}
boolean setPassword = false;
if (isPersistCredentials() && (!credential.isNew() || credential.getUser() != null))
{
if (credential.isNew())
{
setPassword = true;
}
else
{
String encodedPassword = password;
if (upcpm != null && upcpm.getCredentialPasswordEncoder() != null && credential.isEncoded())
{
CredentialPasswordEncoder encoder = upcpm.getCredentialPasswordEncoder();
if (upcpm.getCredentialPasswordEncoder() instanceof AlgorithmUpgradeCredentialPasswordEncoder)
{
encodedPassword = ((AlgorithmUpgradeCredentialPasswordEncoder)encoder).encode(credential, password);
}
else
{
encodedPassword = encoder.encode(userName, password);
}
}
if (!credential.getPassword().equals(encodedPassword))
{
setPassword = true;
}
}
if (setPassword)
{
credential.setPassword(null, password);
boolean synchronizing = SynchronizationStateAccess.isSynchronizing();
try
{
SynchronizationStateAccess.setSynchronizing(Boolean.TRUE);
storePasswordCredential(credential);
}
finally
{
SynchronizationStateAccess.setSynchronizing(synchronizing ? Boolean.TRUE : Boolean.FALSE);
}
}
if (upcpm != null)
{
if (upcpm.onLoad(credential, userName))
{
upcsm.storePasswordCredential(credential);
}
if (credential.isEnabled() && !credential.isExpired())
{
if (upcpm.authenticate(credential, userName, password, true))
{
upcsm.storePasswordCredential(credential);
}
if (!credential.isEnabled() || credential.isExpired())
{
throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER, userName));
}
else if (credential.getAuthenticationFailures() != 0)
{
throw new SecurityException(SecurityException.INVALID_PASSWORD);
}
}
}
}
if (credential.getUser() == null)
{
if (!credential.isNew())
{
try
{
upcam.loadPasswordCredentialUser(credential);
}