Search in sources :

Example 26 with ConnectionEntryReader

use of org.forgerock.opendj.ldif.ConnectionEntryReader 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 27 with ConnectionEntryReader

use of org.forgerock.opendj.ldif.ConnectionEntryReader 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 28 with ConnectionEntryReader

use of org.forgerock.opendj.ldif.ConnectionEntryReader 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 29 with ConnectionEntryReader

use of org.forgerock.opendj.ldif.ConnectionEntryReader 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)

Example 30 with ConnectionEntryReader

use of org.forgerock.opendj.ldif.ConnectionEntryReader in project OpenAM by OpenRock.

the class SMSLdapObject method search.

/**
     * Returns LDAP entries that match the filter, using the start DN provided
     * in method
     */
public Iterator<SMSDataEntry> search(SSOToken token, String startDN, String filter, int numOfEntries, int timeLimit, boolean sortResults, boolean ascendingOrder, Set<String> excludes) throws SSOException, SMSException {
    Connection conn = getConnection(adminPrincipal);
    ConnectionEntryReader results = searchObjectsEx(token, startDN, filter, numOfEntries, timeLimit, sortResults, ascendingOrder, conn);
    return new SearchResultIterator(results, excludes, conn);
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) Connection(org.forgerock.opendj.ldap.Connection)

Aggregations

ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)48 LdapException (org.forgerock.opendj.ldap.LdapException)38 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)38 Connection (org.forgerock.opendj.ldap.Connection)35 ByteString (org.forgerock.opendj.ldap.ByteString)26 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)26 SearchResultReferenceIOException (org.forgerock.opendj.ldap.SearchResultReferenceIOException)19 ResultCode (org.forgerock.opendj.ldap.ResultCode)18 HashSet (java.util.HashSet)17 Attribute (org.forgerock.opendj.ldap.Attribute)16 PolicyException (com.sun.identity.policy.PolicyException)12 SSOException (com.iplanet.sso.SSOException)11 IOException (java.io.IOException)10 InvalidNameException (com.sun.identity.policy.InvalidNameException)9 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)9 SMSException (com.sun.identity.sm.SMSException)7 ArrayList (java.util.ArrayList)7 LinkedHashSet (java.util.LinkedHashSet)7 DN (org.forgerock.opendj.ldap.DN)7 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)5