com.unboundid.ldap.sdk.LDAPConnection connection = <some connection> com.unboundid.ldap.sdk.SearchRequest request = new SearchRequest(<your parameters>); request.setSizeLimit(<your limit>); SearchResult result = connection.search(request);
/** * Creates a search request from this protocol op. * * @param controls The set of controls to include in the search request. * It may be empty or {@code null} if no controls should be * included. * * @return The search request that was created. */ public SearchRequest toSearchRequest(final Control... controls) { final String[] attrArray = new String[attributes.size()]; attributes.toArray(attrArray); return new SearchRequest(null, controls, baseDN, scope, derefPolicy, sizeLimit, timeLimit, typesOnly, filter, attrArray); }
/** * Creates a search request from this protocol op. * * @param controls The set of controls to include in the search request. * It may be empty or {@code null} if no controls should be * included. * * @return The search request that was created. */ public SearchRequest toSearchRequest(final Control... controls) { final String[] attrArray = new String[attributes.size()]; attributes.toArray(attrArray); return new SearchRequest(null, controls, baseDN, scope, derefPolicy, sizeLimit, timeLimit, typesOnly, filter, attrArray); }
/** * Creates a search request containing the base DN, scope, filter, and * requested attributes from this LDAP URL. * * @return The search request created from the base DN, scope, filter, and * requested attributes from this LDAP URL. */ public SearchRequest toSearchRequest() { return new SearchRequest(baseDN.toString(), scope, filter, attributes); }
/** * Creates a search request containing the base DN, scope, filter, and * requested attributes from this LDAP URL. * * @return The search request created from the base DN, scope, filter, and * requested attributes from this LDAP URL. */ public SearchRequest toSearchRequest() { return new SearchRequest(baseDN.toString(), scope, filter, attributes); }
/** * {@inheritDoc} * <BR><BR> * This method may be used regardless of whether the server is listening for * client connections, and regardless of whether search operations are allowed * in the server. */ public SearchResult search(final String baseDN, final SearchScope scope, final Filter filter, final String... attributes) throws LDAPSearchException { return search(new SearchRequest(baseDN, scope, filter, attributes)); }
/** * {@inheritDoc} * <BR><BR> * This method may be used regardless of whether the server is listening for * client connections, and regardless of whether search operations are allowed * in the server. */ public SearchResultEntry searchForEntry(final String baseDN, final SearchScope scope, final Filter filter, final String... attributes) throws LDAPSearchException { return searchForEntry(new SearchRequest(baseDN, scope, filter, attributes)); }
/** * {@inheritDoc} * <BR><BR> * This method may be used regardless of whether the server is listening for * client connections, and regardless of whether search operations are allowed * in the server. */ public SearchResult search(final SearchResultListener searchResultListener, final String baseDN, final SearchScope scope, final Filter filter, final String... attributes) throws LDAPSearchException { return search(new SearchRequest(searchResultListener, baseDN, scope, filter, attributes)); }
/** * Counts the number of entries under the base DN. * * @return The entry count. */ public int countEntries() { SearchRequest request = new SearchRequest( config.ldapDirectory.baseDN.toString(), SearchScope.ONE, MATCH_ANY_FILTER, SearchRequest.NO_ATTRIBUTES); final AtomicInteger count = new AtomicInteger(); doSearch(request, entry -> count.incrementAndGet()); return count.intValue(); }
/** * Counts the number of entries under the base DN. * * @return The entry count. */ public int countEntries() { SearchRequest request = new SearchRequest( config.ldapDirectory.baseDN.toString(), SearchScope.ONE, MATCH_ANY_FILTER, SearchRequest.NO_ATTRIBUTES); final AtomicInteger count = new AtomicInteger(); doSearch(request, entry -> count.incrementAndGet()); return count.intValue(); }
List<String> getRoles() throws LDAPException { final SearchRequest searchRequest = new SearchRequest( roleBaseDN, ONE, "(uniqueMember=" + userDN + ")", CN); final SearchResult searchResult = ldapInterface.search(searchRequest); return searchResult.getSearchEntries() .stream() .flatMap(entry -> stream(entry.getAttributeValues("CN"))) .collect(toList()); }
/** * {@inheritDoc} * <BR><BR> * This method may be used regardless of whether the server is listening for * client connections, and regardless of whether search operations are allowed * in the server. */ public SearchResult search(final String baseDN, final SearchScope scope, final String filter, final String... attributes) throws LDAPSearchException { return search(new SearchRequest(baseDN, scope, parseFilter(filter), attributes)); }
/** * Retrieves all entries from the LDAP directory under the base DN that * match the specified filter. * * @param filter The LDAP search filter. Must not be {@code null}. * @param consumer Consumes the matching directory entries. Must not be * {@code null}. */ public void retrieveEntries(final Filter filter, final Consumer<ReadOnlyEntry> consumer) { SearchRequest searchRequest = new SearchRequest( config.ldapDirectory.baseDN.toString(), SearchScope.ONE, filter, SearchRequest.ALL_USER_ATTRIBUTES); doSearch(searchRequest, consumer); }
/** * {@inheritDoc} * <BR><BR> * This method may be used regardless of whether the server is listening for * client connections, and regardless of whether search operations are allowed * in the server. */ public SearchResult search(final SearchResultListener searchResultListener, final String baseDN, final SearchScope scope, final String filter, final String... attributes) throws LDAPSearchException { return search(new SearchRequest(searchResultListener, baseDN, scope, parseFilter(filter), attributes)); }
/** * Retrieves all entries from the LDAP directory under the base DN that * match the specified filter. * * @param filter The LDAP search filter. Must not be {@code null}. * @param consumer Consumes the matching directory entries. Must not be * {@code null}. */ public void retrieveEntries(final Filter filter, final Consumer<ReadOnlyEntry> consumer) { SearchRequest searchRequest = new SearchRequest( config.ldapDirectory.baseDN.toString(), SearchScope.ONE, filter, SearchRequest.ALL_USER_ATTRIBUTES); doSearch(searchRequest, consumer); }
/** * {@inheritDoc} * <BR><BR> * This method may be used regardless of whether the server is listening for * client connections, and regardless of whether search operations are allowed * in the server. */ public SearchResultEntry searchForEntry(final String baseDN, final SearchScope scope, final String filter, final String... attributes) throws LDAPSearchException { return searchForEntry(new SearchRequest(baseDN, scope, parseFilter(filter), attributes)); }
/** * {@inheritDoc} * <BR><BR> * This method may be used regardless of whether the server is listening for * client connections, and regardless of whether search operations are allowed * in the server. */ public SearchResult search(final String baseDN, final SearchScope scope, final DereferencePolicy derefPolicy, final int sizeLimit, final int timeLimit, final boolean typesOnly, final String filter, final String... attributes) throws LDAPSearchException { return search(new SearchRequest(baseDN, scope, derefPolicy, sizeLimit, timeLimit, typesOnly, parseFilter(filter), attributes)); }
private SearchRequest createSearchRequest(String searchDN) { List<String> attributes = new ArrayList<String>(); attributes.add("cn"); addAttribute(attributes, givenNameAttribute); addAttribute(attributes, surNameAttribute); addAttribute(attributes, localeAttribute); addAttribute(attributes, organizationAttribute); addAttribute(attributes, divisionAttribute); addAttribute(attributes, rolesAttribute); SearchRequest request = new SearchRequest(searchDN, SearchScope.SUB, Filter.createEqualityFilter( "objectclass", "person"), attributes.toArray(new String[attributes.size()])); return request; }
/** * {@inheritDoc} */ public SearchRequest duplicate(final Control[] controls) { final SearchRequest r = new SearchRequest(searchResultListener, controls, baseDN, scope, derefPolicy, sizeLimit, timeLimit, typesOnly, filter, attributes); if (followReferralsInternal() != null) { r.setFollowReferrals(followReferralsInternal()); } r.setResponseTimeoutMillis(getResponseTimeoutMillis(null)); return r; }
/** * {@inheritDoc} */ public SearchRequest duplicate(final Control[] controls) { final SearchRequest r = new SearchRequest(searchResultListener, controls, baseDN, scope, derefPolicy, sizeLimit, timeLimit, typesOnly, filter, attributes); if (followReferralsInternal() != null) { r.setFollowReferrals(followReferralsInternal()); } r.setResponseTimeoutMillis(getResponseTimeoutMillis(null)); return r; }