Search in sources :

Example 16 with SearchRequest

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());
}
Also used : LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) Arrays(java.util.Arrays) Entry(com.unboundid.ldap.sdk.Entry) TrustAllX509TrustManager(org.graylog2.security.TrustAllX509TrustManager) Attribute(com.unboundid.ldap.sdk.Attribute) LoggerFactory(org.slf4j.LoggerFactory) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Singleton(javax.inject.Singleton) Base64(com.unboundid.util.Base64) BindRequest(com.unboundid.ldap.sdk.BindRequest) MessageFormat(java.text.MessageFormat) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) Inject(javax.inject.Inject) LDAPBindException(com.unboundid.ldap.sdk.LDAPBindException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) GeneralSecurityException(java.security.GeneralSecurityException) ImmutableList(com.google.common.collect.ImmutableList) Locale(java.util.Locale) SSLUtil(com.unboundid.util.ssl.SSLUtil) Objects.requireNonNull(java.util.Objects.requireNonNull) SearchRequest(com.unboundid.ldap.sdk.SearchRequest) Named(javax.inject.Named) BindResult(com.unboundid.ldap.sdk.BindResult) LDAPException(com.unboundid.ldap.sdk.LDAPException) ResultCode(com.unboundid.ldap.sdk.ResultCode) LDAPTestUtils(com.unboundid.util.LDAPTestUtils) TLSProtocolsConfiguration(org.graylog2.configuration.TLSProtocolsConfiguration) ImmutableSet(com.google.common.collect.ImmutableSet) EncryptedValue(org.graylog2.security.encryption.EncryptedValue) Logger(org.slf4j.Logger) StaticUtils.isValidUTF8(com.unboundid.util.StaticUtils.isValidUTF8) TrustManagerProvider(org.graylog2.security.TrustManagerProvider) LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions) Set(java.util.Set) FailoverServerSet(com.unboundid.ldap.sdk.FailoverServerSet) Ints(com.google.common.primitives.Ints) StartTLSExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest) SocketFactory(javax.net.SocketFactory) SearchResult(com.unboundid.ldap.sdk.SearchResult) StaticUtils.toUTF8String(com.unboundid.util.StaticUtils.toUTF8String) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) EncryptedValueService(org.graylog2.security.encryption.EncryptedValueService) Optional(java.util.Optional) Filter(com.unboundid.ldap.sdk.Filter) SearchScope(com.unboundid.ldap.sdk.SearchScope) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) SearchRequest(com.unboundid.ldap.sdk.SearchRequest) SearchResult(com.unboundid.ldap.sdk.SearchResult) StaticUtils.toUTF8String(com.unboundid.util.StaticUtils.toUTF8String)

Aggregations

SearchRequest (com.unboundid.ldap.sdk.SearchRequest)16 SearchResult (com.unboundid.ldap.sdk.SearchResult)16 LDAPException (com.unboundid.ldap.sdk.LDAPException)13 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)8 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)5 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)4 SimplePagedResultsControl (com.unboundid.ldap.sdk.controls.SimplePagedResultsControl)4 InvalidSimplePageControlException (org.gluu.persist.ldap.exception.InvalidSimplePageControlException)4 LDAPSearchException (com.unboundid.ldap.sdk.LDAPSearchException)3 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)3 MappingException (org.gluu.persist.exception.mapping.MappingException)3 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)3 DuplicateEntryException (org.gluu.persist.exception.operation.DuplicateEntryException)3 SearchException (org.gluu.persist.exception.operation.SearchException)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Attribute (com.unboundid.ldap.sdk.Attribute)2 BindResult (com.unboundid.ldap.sdk.BindResult)2 SearchResultReference (com.unboundid.ldap.sdk.SearchResultReference)2 SearchScope (com.unboundid.ldap.sdk.SearchScope)2 ArrayList (java.util.ArrayList)2