Search in sources :

Example 1 with PasswordPolicy

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);
    }
}
Also used : ResultResponse(org.apache.directory.api.ldap.model.message.ResultResponse) PasswordException(org.apache.directory.ldap.client.template.exception.PasswordException) PasswordPolicy(org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ResultCodeEnum(org.apache.directory.api.ldap.model.message.ResultCodeEnum)

Example 2 with PasswordPolicy

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;
}
Also used : PasswordException(org.apache.directory.fortress.core.PasswordException) FinderException(org.apache.directory.fortress.core.FinderException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) ObjectFactory(org.apache.directory.fortress.core.model.ObjectFactory) PasswordPolicy(org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy) BindResponse(org.apache.directory.api.ldap.model.message.BindResponse) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Session(org.apache.directory.fortress.core.model.Session) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

PasswordPolicy (org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy)2 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)1 BindResponse (org.apache.directory.api.ldap.model.message.BindResponse)1 ResultCodeEnum (org.apache.directory.api.ldap.model.message.ResultCodeEnum)1 ResultResponse (org.apache.directory.api.ldap.model.message.ResultResponse)1 FinderException (org.apache.directory.fortress.core.FinderException)1 PasswordException (org.apache.directory.fortress.core.PasswordException)1 ObjectFactory (org.apache.directory.fortress.core.model.ObjectFactory)1 Session (org.apache.directory.fortress.core.model.Session)1 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)1 PasswordException (org.apache.directory.ldap.client.template.exception.PasswordException)1