Search in sources :

Example 16 with SearchRequest

use of org.forgerock.opendj.ldap.requests.SearchRequest in project admin-console-beta by connexta.

the class ServerGuesser method getClaimAttributeOptions.

public Set<String> getClaimAttributeOptions(String baseUserDn) {
    try {
        // Find all object classes with names like *person* in the core schema
        // this will catch person, organizationalPerson, inetOrgPerson, etc. if present
        SortedSet<String> attributes = extractAttributes(Schema.getCoreSchema().getObjectClasses(), oc -> oc.getNameOrOID().toLowerCase().matches(".*person.*"));
        // Find any given user with the clearance attribute
        SearchRequest clearanceReq = Requests.newSearchRequest(DN.valueOf(baseUserDn), SearchScope.WHOLE_SUBTREE, Filter.present("2.16.840.1.101.2.2.1.203"), "objectClass");
        ConnectionEntryReader clearanceReader = connection.search(clearanceReq);
        if (clearanceReader.hasNext()) {
            SearchResultEntry entry = clearanceReader.readEntry();
            RootDSE rootDSE = RootDSE.readRootDSE(connection);
            DN subschemaDN = rootDSE.getSubschemaSubentry();
            Schema subschema = Schema.readSchema(connection, subschemaDN);
            // Check against both the subschema and the default schema
            attributes.addAll(extractAttributes(Entries.getObjectClasses(entry, subschema), STRUCT_OR_AUX));
            attributes.addAll(extractAttributes(Entries.getObjectClasses(entry), STRUCT_OR_AUX));
        }
        return attributes;
    } catch (SearchResultReferenceIOException | LdapException e) {
        LOGGER.warn("Error retrieving attributes from LDAP server; this may indicate a configuration issue with config.");
        return Collections.emptySet();
    }
}
Also used : SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) Schema(org.forgerock.opendj.ldap.schema.Schema) DN(org.forgerock.opendj.ldap.DN) ByteString(org.forgerock.opendj.ldap.ByteString) SearchResultReferenceIOException(org.forgerock.opendj.ldap.SearchResultReferenceIOException) LdapException(org.forgerock.opendj.ldap.LdapException) RootDSE(org.forgerock.opendj.ldap.RootDSE) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 17 with SearchRequest

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

the class SMSLdapObject method getSubEntries.

private Set<String> getSubEntries(SSOToken token, String dn, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException, SSOException {
    SearchRequest request = getSearchRequest(dn, filter, SearchScope.SINGLE_LEVEL, numOfEntries, 0, sortResults, ascendingOrder, getNamingAttribute(), O_ATTR);
    int retry = 0;
    Set<String> answer = new LinkedHashSet<>();
    ConnectionEntryReader results;
    while (retry <= connNumRetry) {
        debug.message("SMSLdapObject.subEntries() retry: {}", retry);
        try (Connection conn = getConnection(token.getPrincipal())) {
            // Get the sub entries
            ConnectionEntryReader iterResults = conn.search(request);
            iterResults.hasNext();
            results = iterResults;
            // Construct the results and return
            try {
                while (results != null && results.hasNext()) {
                    try {
                        if (results.isReference()) {
                            debug.warning("Skipping reference result: {}", results.readReference());
                            continue;
                        }
                        SearchResultEntry entry = results.readEntry();
                        // Workaround for 3823, where (objectClass=*) is used
                        if (entry.getName().toString().toLowerCase().startsWith("ou=")) {
                            answer.add(entry.getName().rdn().getFirstAVA().getAttributeValue().toString());
                        }
                    } catch (SearchResultReferenceIOException e) {
                        debug.error("SMSLdapObject.subEntries: Reference should be handled already for dn {}", dn, e);
                    }
                }
            } catch (LdapException e) {
                debug.warning("SMSLdapObject.subEntries: Error in obtaining sub-entries: {}", dn, e);
                throw new SMSException(e, "sms-entry-cannot-obtain");
            }
            break;
        } catch (LdapException e) {
            ResultCode errorCode = e.getResult().getResultCode();
            if (errorCode.equals(ResultCode.NO_SUCH_OBJECT)) {
                debug.message("SMSLdapObject.subEntries(): entry not present: {}", dn);
                break;
            }
            if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
                debug.warning("SMSLdapObject.subEntries: Unable to search for sub-entries: {}", dn, e);
                throw new SMSException(e, "sms-entry-cannot-search");
            }
            retry++;
            try {
                Thread.sleep(connRetryInterval);
            } catch (InterruptedException ex) {
            // ignored
            }
        }
    }
    debug.message("SMSLdapObject.subEntries: Successfully obtained sub-entries for {}", dn);
    return answer;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) SearchResultReferenceIOException(org.forgerock.opendj.ldap.SearchResultReferenceIOException) ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 18 with SearchRequest

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

the class SMSLdapObject method searchObjects.

private ConnectionEntryReader searchObjects(SSOToken token, String startDN, String filter, int numOfEntries, int timeLimit, boolean sortResults, boolean ascendingOrder, Connection conn) throws SSOException, SMSException {
    ConnectionEntryReader results = null;
    int retry = 0;
    SearchRequest request = getSearchRequest(startDN, filter, SearchScope.WHOLE_SUBTREE, numOfEntries, timeLimit);
    while (retry <= connNumRetry) {
        if (debug.messageEnabled()) {
            debug.message("SMSLdapObject.search() retry: " + retry);
        }
        try {
            results = conn.search(request);
            results.hasNext();
            return results;
        } catch (LdapException e) {
            ResultCode errorCode = e.getResult().getResultCode();
            if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
                debug.warning("SMSLdapObject.search(): LDAP exception in search for filter match: {}", filter, e);
                throw new SMSException(e, "sms-error-in-searching");
            }
            retry++;
            try {
                Thread.sleep(connRetryInterval);
            } catch (InterruptedException ex) {
            //ignored
            }
        }
    }
    return null;
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) SMSException(com.sun.identity.sm.SMSException) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 19 with SearchRequest

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

the class SMSLdapObject method searchObjectsEx.

private ConnectionEntryReader searchObjectsEx(SSOToken token, String startDN, String filter, int numOfEntries, int timeLimit, boolean sortResults, boolean ascendingOrder, Connection conn) throws SSOException, SMSException {
    ConnectionEntryReader results = null;
    int retry = 0;
    SearchRequest request = getSearchRequest(startDN, filter, SearchScope.WHOLE_SUBTREE, numOfEntries, timeLimit, SMSEntry.ATTR_KEYVAL, SMSEntry.ATTR_XML_KEYVAL);
    while (retry <= connNumRetry) {
        if (debug.messageEnabled()) {
            debug.message("SMSLdapObject.search() retry: " + retry);
        }
        try {
            ConnectionEntryReader iterResults = conn.search(request);
            iterResults.hasNext();
            results = iterResults;
            break;
        } catch (LdapException e) {
            ResultCode errorCode = e.getResult().getResultCode();
            if (errorCode.equals(ResultCode.SIZE_LIMIT_EXCEEDED)) {
                debug.warning("SMSLdapObject.search: size limit {} exceeded", numOfEntries);
                break;
            }
            if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
                debug.warning("SMSLdapObject.search(): LDAP exception in search for filter match: {}", filter, e);
                throw new SMSException(e, "sms-error-in-searching");
            }
            retry++;
            try {
                Thread.sleep(connRetryInterval);
            } catch (InterruptedException ex) {
            //ignored
            }
        }
    }
    return results;
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) SMSException(com.sun.identity.sm.SMSException) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 20 with SearchRequest

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

the class SMSLdapObject method getOrgNames.

private Set<String> getOrgNames(SSOToken token, String dn, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException, SSOException {
    ConnectionEntryReader results = null;
    int retry = 0;
    SearchRequest request = getSearchRequest(dn, filter, SearchScope.WHOLE_SUBTREE, numOfEntries, 0, sortResults, ascendingOrder, getOrgNamingAttribute(), O_ATTR);
    while (retry <= connNumRetry) {
        if (debug.messageEnabled()) {
            debug.message("SMSLdapObject.getOrgNames() retry: " + retry);
        }
        try (Connection conn = getConnection(token.getPrincipal())) {
            // Get the organization names
            results = conn.search(request);
            results.hasNext();
            return toDNStrings(results, dn, ORG_CANNOT_OBTAIN);
        } catch (LdapException e) {
            ResultCode errorCode = e.getResult().getResultCode();
            if (!retryErrorCodes.contains(errorCode) || retry == connNumRetry) {
                if (errorCode.equals(ResultCode.NO_SUCH_OBJECT)) {
                    debug.message("SMSLdapObject.getOrgNames(): org not present: {}", dn);
                    break;
                } else {
                    debug.warning("SMSLdapObject.getOrgNames: Unable to search for organization names: {}", dn, e);
                    throw new SMSException(e, "sms-org-cannot-search");
                }
            }
            retry++;
            try {
                Thread.sleep(connRetryInterval);
            } catch (InterruptedException ex) {
            // ignored
            }
        }
    }
    return Collections.emptySet();
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Aggregations

SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)32 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)26 LdapException (org.forgerock.opendj.ldap.LdapException)25 Connection (org.forgerock.opendj.ldap.Connection)20 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)19 ByteString (org.forgerock.opendj.ldap.ByteString)18 ResultCode (org.forgerock.opendj.ldap.ResultCode)15 HashSet (java.util.HashSet)13 SearchResultReferenceIOException (org.forgerock.opendj.ldap.SearchResultReferenceIOException)10 Attribute (org.forgerock.opendj.ldap.Attribute)9 DN (org.forgerock.opendj.ldap.DN)9 SSOException (com.iplanet.sso.SSOException)8 PolicyException (com.sun.identity.policy.PolicyException)8 InvalidNameException (com.sun.identity.policy.InvalidNameException)7 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)7 LinkedHashSet (java.util.LinkedHashSet)7 SMSException (com.sun.identity.sm.SMSException)6 Filter (org.forgerock.opendj.ldap.Filter)6 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)5 ArrayList (java.util.ArrayList)4