[jira] [Comment Edited] (DIRAPI-399) Cannot paginate SearchCursor via SearchRequest when SearchResultReference(s) picked up
[ https://issues.apache.org/jira/browse/DIRAPI-399?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17823128#comment-17823128 ] Thomas Jodes edited comment on DIRAPI-399 at 3/4/24 1:22 PM: - Edit: I switched paged search as seen above not to use the EntryCursorImpl, but to use [SearchCursor like here|https://directory.apache.org/api/user-guide/2.3-searching.html]. Just to work with the SearchCursor and to use the cast to SearchResultEntry. Interestingly, not a single SearchResultReference comes up, so referals absent here. When wrapping the searchResult in the EntryCursorImpl (EntryCursor cursor = new EntryCursorImpl(searchCursor)), the references are in the first page results. was (Author: JIRAUSER286693): Edit: I switched paged search as seen above not to use the EntryCursorImpl, but to use [SearchCursor like here|[http://example.com|https://directory.apache.org/api/user-guide/2.3-searching.html]]. Just to work with the SearchCursor and to use the cast to SearchResultEntry. Interestingly, not a single SearchResultReference comes up, so referals absent here. When wrapping the searchResult in the EntryCursorImpl (EntryCursor cursor = new EntryCursorImpl(searchCursor)), the references are in the first page results. > Cannot paginate SearchCursor via SearchRequest when SearchResultReference(s) > picked up > -- > > Key: DIRAPI-399 > URL: https://issues.apache.org/jira/browse/DIRAPI-399 > Project: Directory Client API > Issue Type: Bug >Affects Versions: 2.1.6 >Reporter: Thomas Jodes >Priority: Major > Attachments: Screenshot from 2024-03-01 15-47-26.png, Screenshot from > 2024-03-01 15-48-52.png > > > As a ldap-api user, I want to search my DIT paginated from a base where also > referrals / > [SearchResultReference|https://github.com/apache/directory-ldap-api/blob/c4fcf46f72601c1729d6d5321e2cdc7126f94b14/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchResultReferenceImpl.java#L28]s > are. > Following paged search code: > > {code:java} > int pageSize = 100; > LdapConnection connection = null; > try { > connection = ldapConnectionPool.getConnection(); > int page = 0; // the current page > PagedResults pagedSearchControl = new PagedResultsImpl(); > pagedSearchControl.setSize(pageSize); > // Loop using the paged search control extension > while(true) { > SearchRequest searchRequest = new SearchRequestImpl() > .ignoreReferrals() > .setDerefAliases(AliasDerefMode.NEVER_DEREF_ALIASES) > .setBase(new Dn(searchBase)) > .setFilter(filter) > .setScope(SearchScope.SUBTREE) > .addAttributes(attributes) > .setTimeLimit(120) > .addControl(pagedSearchControl); > SearchCursorImpl searchCursor = (SearchCursorImpl) > connection.search(searchRequest); > try (EntryCursor cursor = new EntryCursorImpl(searchCursor)) { > while (cursor.next()) { > Entry e = cursor.get(); > log.info("element: {}", e.get("sAMAccountName")); > results.add(e); > } > SearchResultDone searchResult = cursor.getSearchResultDone(); > pagedSearchControl = > (PagedResults)searchResult.getControl(PagedResults.OID); > if (searchResult.getLdapResult().getResultCode() == > ResultCodeEnum.UNWILLING_TO_PERFORM) { > throw new LdapException("Directory cannot handle > pagination!"); > } > } catch (CursorException e) { > log.error("Unexpected cursor exception occurred!", e); > } > // Check if pagination is exhausted (all eligible entries have been > read) > if (Strings.isEmpty(pagedSearchControl.getCookie())) { > log.info("Exiting paged search at page: " + ++page); > break; > } > // Prepare the next iteration > pagedSearchControl.setSize(pageSize); > } > // here we want to do s.th. with our 'results' reference; > } catch (LdapException e) { > log.error("Unexpected ldap exception occurred!", e); > } catch (IOException e) { > log.error("Unexpected I/O exception occurred!", e); > } finally { > if (connection != null) { > ldapConnectionPool.releaseConnection(connection); // put the > session/connection back to its pool > } > } {code} > > *Expected behaviour:* > all elements in the base are picked up in the 'results' list, all paginated > and
[jira] [Comment Edited] (DIRAPI-399) Cannot paginate SearchCursor via SearchRequest when SearchResultReference(s) picked up
[ https://issues.apache.org/jira/browse/DIRAPI-399?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17822743#comment-17822743 ] Emmanuel Lécharny edited comment on DIRAPI-399 at 3/2/24 3:01 AM: -- Hi, just to clarify, you are sending this request to an Active Directory server that does not seems to respect the IgnoreReferals flag, thus returning some referals, how is it a LDAP API issue? I'm missing something? was (Author: elecharny): Hi, just to clarify, you are sending this request to an Active Directory server that does not seems to respect the IgnoreReferals flag, thus returning some referals, how is it a LDAP API issue? > Cannot paginate SearchCursor via SearchRequest when SearchResultReference(s) > picked up > -- > > Key: DIRAPI-399 > URL: https://issues.apache.org/jira/browse/DIRAPI-399 > Project: Directory Client API > Issue Type: Bug >Affects Versions: 2.1.6 >Reporter: Thomas Jodes >Priority: Major > Attachments: Screenshot from 2024-03-01 15-47-26.png, Screenshot from > 2024-03-01 15-48-52.png > > > As a ldap-api user, I want to search my DIT paginated from a base where also > referrals / > [SearchResultReference|https://github.com/apache/directory-ldap-api/blob/c4fcf46f72601c1729d6d5321e2cdc7126f94b14/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/SearchResultReferenceImpl.java#L28]s > are. > Following paged search code: > > {code:java} > int pageSize = 100; > LdapConnection connection = null; > try { > connection = ldapConnectionPool.getConnection(); > int page = 0; // the current page > PagedResults pagedSearchControl = new PagedResultsImpl(); > pagedSearchControl.setSize(pageSize); > // Loop using the paged search control extension > while(true) { > SearchRequest searchRequest = new SearchRequestImpl() > .ignoreReferrals() > .setDerefAliases(AliasDerefMode.NEVER_DEREF_ALIASES) > .setBase(new Dn(searchBase)) > .setFilter(filter) > .setScope(SearchScope.SUBTREE) > .addAttributes(attributes) > .setTimeLimit(120) > .addControl(pagedSearchControl); > SearchCursorImpl searchCursor = (SearchCursorImpl) > connection.search(searchRequest); > try (EntryCursor cursor = new EntryCursorImpl(searchCursor)) { > while (cursor.next()) { > Entry e = cursor.get(); > log.info("element: {}", e.get("sAMAccountName")); > results.add(e); > } > SearchResultDone searchResult = cursor.getSearchResultDone(); > pagedSearchControl = > (PagedResults)searchResult.getControl(PagedResults.OID); > if (searchResult.getLdapResult().getResultCode() == > ResultCodeEnum.UNWILLING_TO_PERFORM) { > throw new LdapException("Directory cannot handle > pagination!"); > } > } catch (CursorException e) { > log.error("Unexpected cursor exception occurred!", e); > } > // Check if pagination is exhausted (all eligible entries have been > read) > if (Strings.isEmpty(pagedSearchControl.getCookie())) { > log.info("Exiting paged search at page: " + ++page); > break; > } > // Prepare the next iteration > pagedSearchControl.setSize(pageSize); > } > // here we want to do s.th. with our 'results' reference; > } catch (LdapException e) { > log.error("Unexpected ldap exception occurred!", e); > } catch (IOException e) { > log.error("Unexpected I/O exception occurred!", e); > } finally { > if (connection != null) { > ldapConnectionPool.releaseConnection(connection); // put the > session/connection back to its pool > } > } {code} > > *Expected behaviour:* > all elements in the base are picked up in the 'results' list, all paginated > and added up by x times a bunch of 100 until everything has been read in the > directory. In the searchFuture at LdapNetworkConnection.searchAsync should be > 101 elements: 100 SearchResultEntryImpl's and one SearchResultDoneImpl. > > *Actual behaviour:* > in the first page there are 100 entries, i.e. 100x SearchResultEntryImpl > elements PLUS (in my case/active directory) 3x SearchResultReferenceImpl > elements plus 1x SerachResultDoneImpl element as the last one in the array of > the searchFuture here:[ >