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