Search in sources :

Example 1 with ChangePwdRequest

use of com.novell.security.nmas.jndi.ldap.ext.ChangePwdRequest in project ldapchai by ldapchai.

the class InetOrgPersonImpl method changePassword.

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

Aggregations

ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)1 ChaiPasswordPolicyException (com.novell.ldapchai.exception.ChaiPasswordPolicyException)1 ChangePwdRequest (com.novell.security.nmas.jndi.ldap.ext.ChangePwdRequest)1 ChangePwdResponse (com.novell.security.nmas.jndi.ldap.ext.ChangePwdResponse)1 ExtendedResponse (javax.naming.ldap.ExtendedResponse)1