use of com.unboundid.ldap.sdk.SearchRequest in project graylog2-server by Graylog2.
the class UnboundLDAPConnector method search.
public ImmutableList<LDAPEntry> search(LDAPConnection connection, String searchBase, Filter filter, String uniqueIdAttribute, Set<String> attributes) throws LDAPException {
final ImmutableSet<String> allAttributes = ImmutableSet.<String>builder().add(OBJECT_CLASS_ATTRIBUTE).addAll(attributes).build();
// TODO: Use LDAPEntrySource for a more memory efficient search
final SearchRequest searchRequest = new SearchRequest(searchBase, SearchScope.SUB, filter, allAttributes.toArray(new String[0]));
searchRequest.setTimeLimitSeconds(requestTimeoutSeconds);
if (LOG.isTraceEnabled()) {
LOG.trace("Search LDAP for <{}> using search base <{}>", filter.toNormalizedString(), searchBase);
}
final SearchResult searchResult = connection.search(searchRequest);
if (searchResult.getSearchEntries().isEmpty()) {
LOG.trace("No LDAP entry found for filter <{}>", filter.toNormalizedString());
return ImmutableList.of();
}
return searchResult.getSearchEntries().stream().map(entry -> createLDAPEntry(entry, uniqueIdAttribute)).collect(ImmutableList.toImmutableList());
}
Aggregations