Search in sources :

Example 46 with ConnectionEntryReader

use of org.forgerock.opendj.ldif.ConnectionEntryReader in project admin-console-beta by connexta.

the class ServerGuesser method getChoices.

private List<String> getChoices(String query) {
    List<String> baseContexts = getBaseContexts();
    List<String> choices = new ArrayList<>();
    for (String baseContext : baseContexts) {
        try (ConnectionEntryReader reader = connection.search(baseContext, SearchScope.WHOLE_SUBTREE, query)) {
            while (reader.hasNext()) {
                if (!reader.isReference()) {
                    SearchResultEntry resultEntry = reader.readEntry();
                    choices.add(resultEntry.getName().toString());
                } else {
                    // TODO RAP 07 Dec 16: What do we need to do with remote references?
                    reader.readReference();
                }
            }
        } catch (IOException e) {
            LOGGER.debug("Error getting choices", e);
        }
    }
    return choices;
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SearchResultReferenceIOException(org.forgerock.opendj.ldap.SearchResultReferenceIOException) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 47 with ConnectionEntryReader

use of org.forgerock.opendj.ldif.ConnectionEntryReader in project admin-console-beta by connexta.

the class ServerGuesser method getBaseContexts.

public List<String> getBaseContexts() {
    try {
        ConnectionEntryReader reader = connection.search("", SearchScope.BASE_OBJECT, "(objectClass=*)", "namingContexts");
        ArrayList<String> contexts = new ArrayList<>();
        while (reader.hasNext()) {
            SearchResultEntry entry = reader.readEntry();
            if (entry.containsAttribute("namingContexts")) {
                contexts.add(entry.getAttribute("namingContexts").firstValueAsString());
            }
        }
        if (contexts.isEmpty()) {
            contexts.add("");
        }
        return contexts;
    } catch (LdapException | SearchResultReferenceIOException e) {
        LOGGER.debug("Error getting baseContext", e);
        return Collections.singletonList("");
    }
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) ArrayList(java.util.ArrayList) SearchResultReferenceIOException(org.forgerock.opendj.ldap.SearchResultReferenceIOException) LdapException(org.forgerock.opendj.ldap.LdapException) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 48 with ConnectionEntryReader

use of org.forgerock.opendj.ldif.ConnectionEntryReader in project admin-console-beta by connexta.

the class LdapTestingUtils method getLdapQueryResults.

/**
     * Executes a query against the ldap connection
     *
     * @param ldapConnection   Ldap connection to run query on
     * @param ldapSearchBaseDN Base DN to run the query on
     * @param ldapQuery        Query to perform
     * @param searchScope      Scope of query
     * @param maxResults       Max number of results to return from query. Use -1 for all results
     * @param attributes       Optional list of attributes for return projection; if null,
     *                         then all attributes will be returned
     * @return list of results
     */
public List<SearchResultEntry> getLdapQueryResults(Connection ldapConnection, String ldapSearchBaseDN, String ldapQuery, SearchScope searchScope, int maxResults, String... attributes) {
    ConnectionEntryReader reader;
    if (attributes == null) {
        reader = ldapConnection.search(ldapSearchBaseDN, searchScope, ldapQuery);
    } else {
        reader = ldapConnection.search(ldapSearchBaseDN, searchScope, ldapQuery, attributes);
    }
    List<SearchResultEntry> entries = new ArrayList<>();
    try {
        while (entries.size() < maxResults && reader.hasNext()) {
            if (!reader.isReference()) {
                SearchResultEntry resultEntry = reader.readEntry();
                entries.add(resultEntry);
            } else {
                reader.readReference();
            }
        }
    } catch (IOException e) {
        reader.close();
    }
    reader.close();
    return entries;
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

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