Search in sources :

Example 61 with SearchResultEntry

use of org.forgerock.opendj.ldap.responses.SearchResultEntry 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=*)", NAMING_CONTEXTS);
        ArrayList<String> contexts = new ArrayList<>();
        while (reader.hasNext()) {
            SearchResultEntry entry = reader.readEntry();
            if (entry.containsAttribute(NAMING_CONTEXTS)) {
                contexts.add(entry.getAttribute(NAMING_CONTEXTS).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) ByteString(org.forgerock.opendj.ldap.ByteString) SearchResultReferenceIOException(org.forgerock.opendj.ldap.SearchResultReferenceIOException) LdapException(org.forgerock.opendj.ldap.LdapException) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 62 with SearchResultEntry

use of org.forgerock.opendj.ldap.responses.SearchResultEntry in project admin-console-beta by connexta.

the class LdapQuery method performFunction.

@Override
public MapField.ListImpl performFunction() {
    List<SearchResultEntry> searchResults;
    List<MapField> convertedSearchResults = new ArrayList<>();
    try (LdapConnectionAttempt connectionAttempt = utils.bindUserToLdapConnection(conn, creds)) {
        addErrorMessages(connectionAttempt);
        if (containsErrorMsgs()) {
            return null;
        }
        searchResults = utils.getLdapQueryResults(connectionAttempt.getResult(), queryBase.getValue(), query.getValue(), SearchScope.WHOLE_SUBTREE, maxQueryResults.getValue() == null ? DEFAULT_MAX_QUERY_RESULTS : maxQueryResults.getValue());
        for (SearchResultEntry entry : searchResults) {
            MapField entryMap = new MapField();
            for (Attribute attri : entry.getAllAttributes()) {
                entryMap.put("name", entry.getName().toString());
                if (!attri.getAttributeDescriptionAsString().toLowerCase().contains("password")) {
                    List<String> attributeValueList = attri.parallelStream().map(ByteString::toString).collect(Collectors.toList());
                    String attributeValue = attributeValueList.size() == 1 ? attributeValueList.get(0) : attributeValueList.toString();
                    entryMap.put(attri.getAttributeDescriptionAsString(), attributeValue);
                }
            }
            convertedSearchResults.add(entryMap);
        }
    } catch (IOException e) {
        LOGGER.warn("Error closing LDAP connection", e);
    }
    return new MapField.ListImpl().addAll(convertedSearchResults);
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) ArrayList(java.util.ArrayList) ByteString(org.forgerock.opendj.ldap.ByteString) IOException(java.io.IOException) LdapConnectionAttempt(org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry) MapField(org.codice.ddf.admin.common.fields.common.MapField)

Aggregations

SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)62 LdapException (org.forgerock.opendj.ldap.LdapException)46 ByteString (org.forgerock.opendj.ldap.ByteString)43 Connection (org.forgerock.opendj.ldap.Connection)43 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)43 Attribute (org.forgerock.opendj.ldap.Attribute)30 HashSet (java.util.HashSet)25 SearchResultReferenceIOException (org.forgerock.opendj.ldap.SearchResultReferenceIOException)24 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)19 IOException (java.io.IOException)18 PolicyException (com.sun.identity.policy.PolicyException)15 ResultCode (org.forgerock.opendj.ldap.ResultCode)15 SSOException (com.iplanet.sso.SSOException)14 DN (org.forgerock.opendj.ldap.DN)11 InvalidNameException (com.sun.identity.policy.InvalidNameException)10 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)10 LinkedAttribute (org.forgerock.opendj.ldap.LinkedAttribute)10 ArrayList (java.util.ArrayList)9 BindResult (org.forgerock.opendj.ldap.responses.BindResult)8 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)7