Search in sources :

Example 6 with ChaiPasswordPolicyException

use of com.novell.ldapchai.exception.ChaiPasswordPolicyException in project ldapchai by ldapchai.

the class UserImpl method changePassword.

public final void changePassword(final String oldPassword, final String newPassword) throws ChaiUnavailableException, ChaiPasswordPolicyException, ChaiOperationException {
    final String quotedOldPwd = '"' + oldPassword + '"';
    final String quotedNewPwd = '"' + newPassword + '"';
    final byte[] littleEndianEncodedOldPwd;
    final byte[] littleEndianEncodedNewPwd;
    try {
        littleEndianEncodedOldPwd = quotedOldPwd.getBytes("UTF-16LE");
        littleEndianEncodedNewPwd = quotedNewPwd.getBytes("UTF-16LE");
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("unexpected error, missing 'UTF-16LE' character encoder", e);
    }
    try {
        replaceBinaryAttribute("unicodePwd", littleEndianEncodedOldPwd, littleEndianEncodedNewPwd);
    } catch (ChaiOperationException e) {
        if (e.getErrorCode() == ChaiError.UNKNOWN) {
            throw new ChaiPasswordPolicyException(e.getMessage(), ChaiError.PASSWORD_BADPASSWORD);
        } else {
            throw new ChaiPasswordPolicyException(e.getMessage(), ChaiErrors.getErrorForMessage(e.getMessage()));
        }
    }
}
Also used : ChaiPasswordPolicyException(com.novell.ldapchai.exception.ChaiPasswordPolicyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Example 7 with ChaiPasswordPolicyException

use of com.novell.ldapchai.exception.ChaiPasswordPolicyException in project ldapchai by ldapchai.

the class InetOrgPersonImpl method setPassword.

public void setPassword(final String newPassword, final boolean enforcePasswordPolicy) throws ChaiUnavailableException, ChaiPasswordPolicyException {
    final boolean useNmasSetting = this.getChaiProvider().getChaiConfiguration().getBooleanSetting(ChaiSetting.EDIRECTORY_ENABLE_NMAS);
    if (!useNmasSetting) {
        try {
            writeStringAttribute(ATTR_PASSWORD, newPassword);
        } catch (ChaiOperationException e) {
            throw new ChaiPasswordPolicyException(e.getMessage(), ChaiErrors.getErrorForMessage(e.getMessage()));
        }
    } else {
        final SetPwdRequest request = new SetPwdRequest();
        request.setData(newPassword);
        request.setObjectDN(this.getEntryDN());
        final ExtendedResponse response;
        try {
            response = getChaiProvider().extendedOperation(request);
        } catch (ChaiOperationException e) {
            throw new ChaiPasswordPolicyException(e.getMessage(), ChaiErrors.getErrorForMessage(e.getMessage()));
        }
        if (response != null) {
            final SetPwdResponse setResponse = (SetPwdResponse) response;
            final int responseCode = setResponse.getNmasRetCode();
            if (responseCode != 0) {
                LOGGER.debug("error setting nmas password: " + responseCode);
                final String errorString = "nmas error " + responseCode;
                throw new ChaiPasswordPolicyException(errorString, ChaiErrors.getErrorForMessage(errorString));
            }
        }
    }
}
Also used : ChaiPasswordPolicyException(com.novell.ldapchai.exception.ChaiPasswordPolicyException) SetPwdRequest(com.novell.security.nmas.jndi.ldap.ext.SetPwdRequest) ExtendedResponse(javax.naming.ldap.ExtendedResponse) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) SetPwdResponse(com.novell.security.nmas.jndi.ldap.ext.SetPwdResponse)

Aggregations

ChaiPasswordPolicyException (com.novell.ldapchai.exception.ChaiPasswordPolicyException)7 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)6 ExtendedResponse (javax.naming.ldap.ExtendedResponse)3 ErrorInformation (password.pwm.error.ErrorInformation)3 PwmError (password.pwm.error.PwmError)3 ChaiUser (com.novell.ldapchai.ChaiUser)2 ChaiError (com.novell.ldapchai.exception.ChaiError)2 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)2 UserIdentity (password.pwm.bean.UserIdentity)2 ChangePwdRequest (com.novell.security.nmas.jndi.ldap.ext.ChangePwdRequest)1 ChangePwdResponse (com.novell.security.nmas.jndi.ldap.ext.ChangePwdResponse)1 PwdPolicyCheckRequest (com.novell.security.nmas.jndi.ldap.ext.PwdPolicyCheckRequest)1 PwdPolicyCheckResponse (com.novell.security.nmas.jndi.ldap.ext.PwdPolicyCheckResponse)1 SetPwdRequest (com.novell.security.nmas.jndi.ldap.ext.SetPwdRequest)1 SetPwdResponse (com.novell.security.nmas.jndi.ldap.ext.SetPwdResponse)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Instant (java.time.Instant)1 Locale (java.util.Locale)1 HelpdeskProfile (password.pwm.config.profile.HelpdeskProfile)1 PwmPasswordPolicy (password.pwm.config.profile.PwmPasswordPolicy)1