Search in sources :

Example 1 with MapField

use of org.codice.ddf.admin.common.fields.common.MapField in project admin-console-beta by connexta.

the class LdapQuery method performFunction.

@Override
public ListField<MapField> performFunction() {
    LdapConnectionAttempt connectionAttempt = utils.bindUserToLdapConnection(conn, creds);
    addResultMessages(connectionAttempt.messages());
    if (!connectionAttempt.connection().isPresent()) {
        return null;
    }
    List<SearchResultEntry> searchResults = utils.getLdapQueryResults(connectionAttempt.connection().get(), dn.getValue(), query.getValue(), SearchScope.WHOLE_SUBTREE, maxQueryResults.getValue());
    List<MapField> convertedSearchResults = new ArrayList<>();
    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);
    }
    return new ListFieldImpl<>(MapField.class).addAll(convertedSearchResults);
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) ArrayList(java.util.ArrayList) ByteString(org.forgerock.opendj.ldap.ByteString) 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

ArrayList (java.util.ArrayList)1 MapField (org.codice.ddf.admin.common.fields.common.MapField)1 LdapConnectionAttempt (org.codice.ddf.admin.ldap.commons.LdapConnectionAttempt)1 Attribute (org.forgerock.opendj.ldap.Attribute)1 ByteString (org.forgerock.opendj.ldap.ByteString)1 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)1