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