public boolean authenticate(String username, String password) throws Exception {
if (log.isTraceEnabled()) {
Tools.logMethodIn(log, LogLevel.TRACE, "authenticate", new Object[] { "userName", username, "password", "****" });
}
User user = findUserByName(username, UserStatus.ANY);
if (user == null) {
if (log.isTraceEnabled()) {
Tools.logMethodOut(log, LogLevel.TRACE, "authenticate", false);
}
return false;
}
if (!user.isEnabled()) {
throw new DisabledUserException(username);
}
boolean authenticated = false;
if (orgService.getConfiguration().isPasswordAsAttribute()) {
authenticated = user.getPassword().equals(password);
} else {
try {
orgService.flush();
IdentitySession session = service_.getIdentitySession();
org.picketlink.idm.api.User idmUser = session.getPersistenceManager().findUser(user.getUserName());
authenticated = session.getAttributesManager().validatePassword(idmUser, password);
} catch (Exception e) {
handleException("Cannot authenticate user: " + username + "; ", e);