Search in sources :

Example 1 with ChaiOperationException

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

the class AbstractProvider method getDirectoryVendor.

public DirectoryVendor getDirectoryVendor() throws ChaiUnavailableException {
    if (cachedDirectoryVendor == null) {
        {
            final DirectoryVendor centralCachedVendor = getProviderFactory().getCentralService().getVendorCache(this.chaiConfig);
            if (centralCachedVendor != null) {
                return centralCachedVendor;
            }
        }
        final String defaultVendor = this.getChaiConfiguration().getSetting(ChaiSetting.DEFAULT_VENDOR);
        if (defaultVendor != null) {
            for (final DirectoryVendor vendor : DirectoryVendor.values()) {
                if (vendor.toString().equals(defaultVendor)) {
                    cachedDirectoryVendor = vendor;
                    return vendor;
                }
            }
        }
        try {
            final ChaiEntry rootDseEntry = ChaiUtility.getRootDSE(this);
            cachedDirectoryVendor = ChaiUtility.determineDirectoryVendor(rootDseEntry);
            getProviderFactory().getCentralService().addVendorCache(this.chaiConfig, cachedDirectoryVendor);
        } catch (ChaiOperationException e) {
            LOGGER.warn("error while attempting to determine directory vendor: " + e.getMessage());
            cachedDirectoryVendor = DirectoryVendor.GENERIC;
        }
    }
    return cachedDirectoryVendor;
}
Also used : ChaiEntry(com.novell.ldapchai.ChaiEntry) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Example 2 with ChaiOperationException

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

the class AbstractProvider method cacheExtendedOperationException.

protected void cacheExtendedOperationException(final ExtendedRequest request, final Exception e) throws ChaiOperationException {
    final boolean cacheFailures = this.getChaiConfiguration().getBooleanSetting(ChaiSetting.EXTENDED_OPERATION_FAILURE_CACHE);
    if (cacheFailures) {
        final ChaiOperationException opExcep = ChaiOperationException.forErrorMessage(e.getMessage());
        if (opExcep.getErrorCode() == ChaiError.UNSUPPORTED_OPERATION) {
            final Map<String, Object> providerProps = this.getProviderProperties();
            final Map<String, Exception> cacheFailureMap = (Map<String, Exception>) providerProps.get(EXTENDED_FAILURE_CACHE_KEY);
            final String requestID = request.getID();
            cacheFailureMap.put(requestID, opExcep);
            LOGGER.trace("caching extended operation for " + requestID);
            throw opExcep;
        }
    }
}
Also used : ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) HashMap(java.util.HashMap) Map(java.util.Map) ChaiException(com.novell.ldapchai.exception.ChaiException) IOException(java.io.IOException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Example 3 with ChaiOperationException

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

the class JNDIProviderImpl method compareStringAttribute.

@LdapOperation
public final boolean compareStringAttribute(final String entryDN, final String attributeName, final String value) throws ChaiUnavailableException, ChaiOperationException {
    activityPreCheck();
    getInputValidator().compareStringAttribute(entryDN, attributeName, value);
    final byte[] ba;
    try {
        ba = value.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new UnsupportedOperationException(e);
    }
    // Set up the search controls
    final SearchControls ctls = new SearchControls();
    // Return no attrs
    ctls.setReturningAttributes(new String[0]);
    // Search object only
    ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
    final LdapContext ldapConnection = getLdapConnection();
    NamingEnumeration<SearchResult> answer = null;
    boolean result = false;
    try {
        answer = ldapConnection.search(addJndiEscape(entryDN), "(" + attributeName + "={0})", new Object[] { ba }, ctls);
        result = answer.hasMore();
    } catch (NamingException e) {
        convertNamingException(e);
    } finally {
        if (answer != null) {
            try {
                answer.close();
            } catch (Exception e) {
            /* action not required */
            }
        }
    }
    return result;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) SearchControls(javax.naming.directory.SearchControls) SearchResult(javax.naming.directory.SearchResult) NamingException(javax.naming.NamingException) InitialLdapContext(javax.naming.ldap.InitialLdapContext) LdapContext(javax.naming.ldap.LdapContext) NamingException(javax.naming.NamingException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) CommunicationException(javax.naming.CommunicationException) SizeLimitExceededException(javax.naming.SizeLimitExceededException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with ChaiOperationException

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

the class JNDIProviderImpl method replaceBinaryAttribute.

@LdapOperation
@ModifyOperation
public final void replaceBinaryAttribute(final String entryDN, final String attributeName, final byte[] oldValue, final byte[] newValue) throws ChaiUnavailableException, ChaiOperationException {
    activityPreCheck();
    getInputValidator().replaceBinaryAttribute(entryDN, attributeName, oldValue, newValue);
    final String jndiBinarySetting = "java.naming.ldap.attributes.binary";
    // Create the ModificationItem
    final ModificationItem[] modificationItem = new ModificationItem[2];
    {
        // Create a BasicAttribute for the old value.
        final BasicAttribute oldValueOperation = new BasicAttribute(attributeName, oldValue);
        // Populate the ModificationItem array with the removal of the old value.
        modificationItem[0] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, oldValueOperation);
        // Create a BasicAttribute for the new value.
        final BasicAttribute newValueOperation = new BasicAttribute(attributeName, newValue);
        // Populate the ModificationItem array with the removal of the old value.
        modificationItem[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, newValueOperation);
    }
    // get ldap connection
    final LdapContext ldapConnection = getLdapConnection();
    // Modify the Attributes.
    try {
        ldapConnection.modifyAttributes(addJndiEscape(entryDN), modificationItem);
        // inform jndi the attribute is binary.
        ldapConnection.addToEnvironment(jndiBinarySetting, attributeName);
    } catch (NamingException e) {
        convertNamingException(e);
    } finally {
        // clean up jndi environment
        try {
            ldapConnection.removeFromEnvironment(jndiBinarySetting);
        } catch (Exception e) {
        // doesnt matter
        }
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) NamingException(javax.naming.NamingException) InitialLdapContext(javax.naming.ldap.InitialLdapContext) LdapContext(javax.naming.ldap.LdapContext) NamingException(javax.naming.NamingException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) CommunicationException(javax.naming.CommunicationException) SizeLimitExceededException(javax.naming.SizeLimitExceededException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with ChaiOperationException

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

the class NmasCrFactory method clearResponseSet.

public static void clearResponseSet(final ChaiUser theUser) throws ChaiUnavailableException, ChaiOperationException {
    final ChaiProvider provider = theUser.getChaiProvider();
    final DeleteLoginConfigRequest request = new DeleteLoginConfigRequest();
    request.setObjectDN(theUser.getEntryDN());
    request.setTag("ChallengeResponseQuestions");
    request.setMethodID(NMASChallengeResponse.METHOD_ID);
    request.setMethodIDLen(NMASChallengeResponse.METHOD_ID.length * 4);
    final DeleteLoginConfigResponse response = (DeleteLoginConfigResponse) provider.extendedOperation(request);
    if (response != null && response.getNmasRetCode() != 0) {
        final String errorMsg = "nmas error clearing loginResponseConfig: " + response.getNmasRetCode();
        LOGGER.debug(errorMsg);
        throw new ChaiOperationException(errorMsg, ChaiError.UNKNOWN);
    }
}
Also used : ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) DeleteLoginConfigRequest(com.novell.security.nmas.jndi.ldap.ext.DeleteLoginConfigRequest) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) DeleteLoginConfigResponse(com.novell.security.nmas.jndi.ldap.ext.DeleteLoginConfigResponse)

Aggregations

ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)66 ErrorInformation (password.pwm.error.ErrorInformation)31 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)28 ChaiUser (com.novell.ldapchai.ChaiUser)24 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)21 UserIdentity (password.pwm.bean.UserIdentity)16 PwmOperationalException (password.pwm.error.PwmOperationalException)15 Map (java.util.Map)12 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)11 IOException (java.io.IOException)10 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)10 PwmApplication (password.pwm.PwmApplication)10 LdapProfile (password.pwm.config.profile.LdapProfile)10 FormConfiguration (password.pwm.config.value.data.FormConfiguration)9 List (java.util.List)8 PwmSession (password.pwm.http.PwmSession)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 ChaiPasswordPolicyException (com.novell.ldapchai.exception.ChaiPasswordPolicyException)6 Instant (java.time.Instant)6