Search in sources :

Example 1 with DecodeException

use of org.forgerock.opendj.ldap.DecodeException in project OpenAM by OpenRock.

the class LDAPAuthUtils method processControls.

private List<Control> processControls(Result result) {
    if (result == null) {
        return Collections.EMPTY_LIST;
    }
    List<Control> controls = new ArrayList<Control>();
    DecodeOptions options = new DecodeOptions();
    Control c;
    try {
        c = result.getControl(PasswordExpiredResponseControl.DECODER, options);
        if (c != null) {
            controls.add(c);
        }
    } catch (DecodeException de) {
        if (debug.warningEnabled()) {
            debug.warning("unable to decode PasswordExpiredResponseControl", de);
        }
    }
    try {
        c = result.getControl(PasswordExpiringResponseControl.DECODER, options);
        if (c != null) {
            controls.add(c);
        }
    } catch (DecodeException de) {
        if (debug.warningEnabled()) {
            debug.warning("unable to decode PasswordExpiringResponseControl", de);
        }
    }
    try {
        c = result.getControl(PasswordPolicyResponseControl.DECODER, options);
        if (c != null) {
            controls.add(c);
        }
    } catch (DecodeException de) {
        if (debug.warningEnabled()) {
            debug.warning("unable to decode PasswordPolicyResponseControl", de);
        }
    }
    return controls;
}
Also used : PasswordExpiringResponseControl(org.forgerock.opendj.ldap.controls.PasswordExpiringResponseControl) PasswordExpiredResponseControl(org.forgerock.opendj.ldap.controls.PasswordExpiredResponseControl) PasswordPolicyRequestControl(org.forgerock.opendj.ldap.controls.PasswordPolicyRequestControl) Control(org.forgerock.opendj.ldap.controls.Control) PasswordPolicyResponseControl(org.forgerock.opendj.ldap.controls.PasswordPolicyResponseControl) ArrayList(java.util.ArrayList) DecodeException(org.forgerock.opendj.ldap.DecodeException) DecodeOptions(org.forgerock.opendj.ldap.DecodeOptions)

Example 2 with DecodeException

use of org.forgerock.opendj.ldap.DecodeException in project OpenAM by OpenRock.

the class LdapQueryBuilder method getEntries.

private Collection<Entry> getEntries(Connection connection) throws CoreTokenException {
    // Prepare the search
    Filter ldapFilter = getLDAPFilter();
    SearchRequest searchRequest = LDAPRequests.newSearchRequest(dataLayerConfiguration.getTokenStoreRootSuffix(), SearchScope.WHOLE_SUBTREE, ldapFilter, requestedAttributes);
    searchRequest.setSizeLimit(sizeLimit);
    if (isPagingResults()) {
        searchRequest = searchRequest.addControl(SimplePagedResultsControl.newControl(true, pageSize, pagingCookie));
    }
    // Perform the search
    Collection<Entry> entries = createResultsList();
    final Result result = handler.performSearch(connection, searchRequest, entries);
    if (isPagingResults()) {
        try {
            SimplePagedResultsControl control = result.getControl(SimplePagedResultsControl.DECODER, new DecodeOptions());
            if (control == null) {
                if (debug.warningEnabled()) {
                    debug.warning("There was no paged result control in the search response, it is recommended to " + "set the CTS user's size-limit at least to " + (pageSize + 1));
                }
                pagingCookie = getEmptyPagingCookie();
            } else {
                pagingCookie = control.getCookie();
            }
        } catch (DecodeException e) {
            throw new CoreTokenException("Failed to decode Paging Cookie", e);
        }
    }
    if (debug.messageEnabled()) {
        debug.message(MessageFormat.format(CoreTokenConstants.DEBUG_HEADER + "Query: matched {0} results\n" + "Search Request: {1}\n" + "Filter: {2}\n" + "Result: {3}", entries.size(), searchRequest, ldapFilter.toString(), result));
    }
    return entries;
}
Also used : SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) Entry(org.forgerock.opendj.ldap.Entry) Filter(org.forgerock.opendj.ldap.Filter) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) SimplePagedResultsControl(org.forgerock.opendj.ldap.controls.SimplePagedResultsControl) DecodeException(org.forgerock.opendj.ldap.DecodeException) DecodeOptions(org.forgerock.opendj.ldap.DecodeOptions) Result(org.forgerock.opendj.ldap.responses.Result)

Example 3 with DecodeException

use of org.forgerock.opendj.ldap.DecodeException in project OpenAM by OpenRock.

the class IndexChangeHandler method handleEntry.

@Override
public boolean handleEntry(SearchResultEntry entry) {
    EntryChangeNotificationResponseControl control = null;
    try {
        // Retrieve details of the policy change.
        control = entry.getControl(EntryChangeNotificationResponseControl.DECODER, new DecodeOptions());
    } catch (DecodeException dE) {
        DEBUG.error("Error occurred attempting to read policy rule change.", dE);
        // Notify observers of the exception and proceed no further.
        observable.notifyObservers(ErrorEventType.SEARCH_FAILURE.createEvent());
        return true;
    }
    // Extract the realm from the DN to be passed as part of the event.
    String dn = entry.getName().toString();
    String orgName = dn.substring(dn.indexOf(SERVICE_DECLARATION) + SERVICE_DECLARATION.length());
    String realm = dnMapper.orgNameToRealmName(orgName);
    // Retrieve all sunxmlKeyValue attributes.
    Attribute attributes = entry.getAttribute(AttributeDescription.valueOf("sunxmlKeyValue"));
    for (ByteString attrValue : attributes) {
        String attStrValue = attrValue.toString();
        if (attStrValue.startsWith(INDEX_PATH_ATT)) {
            // Extract the path index out of the attribute value.
            String pathIndex = attStrValue.substring(INDEX_PATH_ATT.length() + 1);
            switch(control.getChangeType()) {
                case MODIFY:
                // this will result in the old index remaining.
                case ADD:
                    observable.notifyObservers(ModificationEventType.ADD.createEvent(pathIndex, realm));
                    break;
                case DELETE:
                    observable.notifyObservers(ModificationEventType.DELETE.createEvent(pathIndex, realm));
                    break;
            }
        }
    }
    return true;
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) EntryChangeNotificationResponseControl(org.forgerock.opendj.ldap.controls.EntryChangeNotificationResponseControl) ByteString(org.forgerock.opendj.ldap.ByteString) DecodeException(org.forgerock.opendj.ldap.DecodeException) DecodeOptions(org.forgerock.opendj.ldap.DecodeOptions)

Aggregations

DecodeException (org.forgerock.opendj.ldap.DecodeException)3 DecodeOptions (org.forgerock.opendj.ldap.DecodeOptions)3 ArrayList (java.util.ArrayList)1 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)1 Attribute (org.forgerock.opendj.ldap.Attribute)1 ByteString (org.forgerock.opendj.ldap.ByteString)1 Entry (org.forgerock.opendj.ldap.Entry)1 Filter (org.forgerock.opendj.ldap.Filter)1 Control (org.forgerock.opendj.ldap.controls.Control)1 EntryChangeNotificationResponseControl (org.forgerock.opendj.ldap.controls.EntryChangeNotificationResponseControl)1 PasswordExpiredResponseControl (org.forgerock.opendj.ldap.controls.PasswordExpiredResponseControl)1 PasswordExpiringResponseControl (org.forgerock.opendj.ldap.controls.PasswordExpiringResponseControl)1 PasswordPolicyRequestControl (org.forgerock.opendj.ldap.controls.PasswordPolicyRequestControl)1 PasswordPolicyResponseControl (org.forgerock.opendj.ldap.controls.PasswordPolicyResponseControl)1 SimplePagedResultsControl (org.forgerock.opendj.ldap.controls.SimplePagedResultsControl)1 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)1 Result (org.forgerock.opendj.ldap.responses.Result)1