Apache Directory LDAP - Search Queries

I am looking for information to perform search queries using the Apache Directory API, but I have not found a single example or any information on how to build SearchRequest with the correct PagedResults control and then do a search.

Do any of you have a clue? Or knows where to find such information?

Or maybe you should recommend me use some other API like unboundid sdk

Thanks in advance and helpful.

+4
source share
3 answers

Take a look at this http://markmail.org/message/43qjepg6shvfvqud OTOH, it is always recommended to post ApacheDS related questions to the user mailing list to get a quick response, we can’t always track SO

+5
source

Today I tried my best to make a connected example with the work of kayyagara.

He has some problems:

  • a special system variable is needed to make this work at all
  • bad cookie breaks it all
  • some settings / lines of code are not needed

The following is a working example:

//Without this you get a class Cast Exception: //java.lang.ClassCastException: org.apache.directory.api.ldap.codec.BasicControlDecorator cannot be cast to org.apache.directory.api.ldap.model.message.controls.PagedResults System.setProperty(StandaloneLdapApiService.CONTROLS_LIST, PagedResultsFactory.class.getName()); PagedResults pagedSearchControl = new PagedResultsDecorator( connection.getCodecService()); pagedSearchControl.setSize(300); // Loop over all the elements List<Entry> results = new ArrayList<Entry>(); boolean hasUnwillingToPerform = false; //inspired by http://markmail.org/message/43qjepg6shvfvqud while (true) { EntryCursor cursor = null; try { SearchRequest searchRequest = new SearchRequestImpl(); searchRequest.setBase(new Dn(searchRoot)); searchRequest.setFilter(searchFilter); searchRequest.setScope(SearchScope.SUBTREE); searchRequest.addAttributes("*"); searchRequest.addControl(pagedSearchControl); cursor = new EntryCursorImpl( connection.search(searchRequest)); while (cursor.next()) { Entry result = cursor.get(); results.add(result); } SearchResultDone result = cursor.getSearchResultDone(); pagedSearchControl = (PagedResults) result .getControl(PagedResults.OID); if (result.getLdapResult().getResultCode() == ResultCodeEnum.UNWILLING_TO_PERFORM) { hasUnwillingToPerform = true; break; } } finally { if (cursor != null) { cursor.close(); } } // check if this is over byte[] cookie = pagedSearchControl.getCookie(); if (Strings.isEmpty(cookie)) { // If so, exit the loop break; } // Prepare the next iteration pagedSearchControl.setSize(300); } if (hasUnwillingToPerform) { throw new IllegalStateException("AD can't handle paging"); } // Cleanup the session connection.unBind(); connection.close(); 
+5
source

This file contains a demonstration of simple posted results control, as described in RFC2696. Compiling and running requires the UnboundID LDAP SDK .

see also

+1
source

Source: https://habr.com/ru/post/1494437/


All Articles