upcsm.storePasswordCredential(credential);
}
public PasswordCredential getAuthenticatedPasswordCredential(String userName, String password) throws SecurityException
{
PasswordCredential credential = upcam.getPasswordCredential(userName);
if (credential == null)
{
throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER, userName));
}
if (upcpm != null)
{
if (upcpm.onLoad(credential, userName))
{
upcsm.storePasswordCredential(credential);
}
if (credential.isEnabled() && !credential.isExpired())
{
if (upcpm.authenticate(credential, userName, password))
{
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);
}
}
}
else
{
if (password == null)
{
throw new SecurityException(SecurityException.PASSWORD_REQUIRED);
}
else if (credential.getPassword() == null || !password.equals(new String(credential.getPassword())))
{
throw new SecurityException(SecurityException.INVALID_PASSWORD);
}
if (!credential.isEnabled() || credential.isExpired())
{
throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER, userName));
}
}
try
{
upcam.loadPasswordCredentialUser(credential);
}
catch (Exception e)
{
throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER, userName), e);
}
if (credential.getUser() == null || !credential.getUser().isEnabled())
{
throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER, userName));
}
return credential;
}