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);
}
Aggregations