Search in sources :

Example 1 with GetPwdResponse

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

the class InetOrgPersonImpl method readPassword.

public final String readPassword() throws ChaiUnavailableException, ChaiOperationException {
    final boolean useNmasSetting = this.getChaiProvider().getChaiConfiguration().getBooleanSetting(ChaiSetting.EDIRECTORY_ENABLE_NMAS);
    if (!useNmasSetting) {
        throw new UnsupportedOperationException("readPassword() is not supported when ChaiSetting.EDIRECTORY_ENABLE_NMAS is false");
    }
    final GetPwdRequest request = new GetPwdRequest("", this.getEntryDN());
    final ExtendedResponse response;
    response = getChaiProvider().extendedOperation(request);
    if (response != null) {
        final GetPwdResponse getResponse = (GetPwdResponse) response;
        final int responseCode = getResponse.getNmasRetCode();
        switch(responseCode) {
            // Success
            case 0:
                return getResponse.getPwdStr();
            // NMAS_E_ENTRY_ATTRIBUTE_NOT_FOUND
            case (-16049):
                LOGGER.debug("readPassword() reports: NMAS_E_ENTRY_ATTRIBUTE_NOT_FOUND " + responseCode);
                throw new ChaiOperationException("object has no password attribute: error " + responseCode, ChaiError.NO_SUCH_ATTRIBUTE);
            default:
                LOGGER.debug("error testing nmas password: " + responseCode);
                throw new ChaiOperationException("error reading nmas password: error " + responseCode, ChaiError.UNKNOWN);
        }
    }
    LOGGER.debug("unknown error retreiving password (null response)");
    throw new ChaiOperationException("unknown error retreiving password (null response)", ChaiError.UNKNOWN);
}
Also used : GetPwdResponse(com.novell.security.nmas.jndi.ldap.ext.GetPwdResponse) GetPwdRequest(com.novell.security.nmas.jndi.ldap.ext.GetPwdRequest) ExtendedResponse(javax.naming.ldap.ExtendedResponse) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Aggregations

ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)1 GetPwdRequest (com.novell.security.nmas.jndi.ldap.ext.GetPwdRequest)1 GetPwdResponse (com.novell.security.nmas.jndi.ldap.ext.GetPwdResponse)1 ExtendedResponse (javax.naming.ldap.ExtendedResponse)1