use of org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy in project directory-ldap-api by apache.
the class AbstractPasswordPolicyResponder method process.
/**
* {@inheritDoc}
*/
@Override
public final PasswordWarning process(PasswordPolicyOperation operation) throws PasswordException {
try {
ResultResponse response = operation.process();
PasswordPolicy passwordPolicy = getPasswordPolicy(response);
ResultCodeEnum resultCode = response.getLdapResult().getResultCode();
if (resultCode == ResultCodeEnum.SUCCESS) {
return success(passwordPolicy);
} else {
throw fail(response, passwordPolicy, resultCode);
}
} catch (LdapException e) {
throw new PasswordException().setLdapException(e);
}
}
use of org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy in project directory-fortress-core by apache.
the class UserDAO method checkPassword.
/**
* @param user
* @return
* @throws org.apache.directory.fortress.core.FinderException, org.apache.directory.fortress.core.PasswordException
*/
Session checkPassword(User user) throws FinderException, PasswordException {
Session session = null;
LdapConnection ld = null;
String userDn = getDn(user.getUserId(), user.getContextId());
try {
session = new ObjectFactory().createSession();
session.setAuthenticated(false);
session.setUserId(user.getUserId());
ld = getUserConnection();
BindResponse bindResponse = bind(ld, userDn, user.getPassword());
String info;
if (bindResponse.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS) {
info = "PASSWORD INVALID for userId [" + user.getUserId() + "], resultCode [" + bindResponse.getLdapResult().getResultCode() + "]";
session.setMsg(info);
session.setErrorId(GlobalErrIds.USER_PW_INVLD);
}
PasswordPolicy respCtrl = getPwdRespCtrl(bindResponse);
if (respCtrl != null) {
// check IETF password policies here
checkPwPolicies(session, respCtrl);
}
if (session.getErrorId() == 0) {
session.setAuthenticated(true);
} else {
// pw invalid or pw policy violation:
throw new PasswordException(session.getErrorId(), session.getMsg());
}
} catch (LdapAuthenticationException e) {
String info = "checkPassword INVALID PASSWORD for userId [" + user.getUserId() + "] exception [" + e + "]";
throw new PasswordException(GlobalErrIds.USER_PW_INVLD, info);
} catch (LdapException e) {
String error = "checkPassword userId [" + user.getUserId() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_READ_FAILED, error, e);
} finally {
closeUserConnection(ld);
}
return session;
}
Aggregations