private NamingEnumeration<SearchResult> searchWithPagination() throws NamingException, IOException { Control[] controlsBackup = null; Object binaryAttributesBackup = null; // backup and set environment if (pageSize != 0 && context instanceof LdapContext) { controlsBackup = ((LdapContext)context).getRequestControls(); ((LdapContext)context).setRequestControls(new Control[]{ new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); } if (binaryAttributes != null && binaryAttributes.size() != 0) { // set attributes which should be returned in binary form binaryAttributesBackup = context.getEnvironment().get(ENV_BINARY_ATTRIBUTES); context.addToEnvironment(ENV_BINARY_ATTRIBUTES, String.join(" ", binaryAttributes)); } NamingEnumeration<SearchResult> results = context.search(new LdapName(searchDn), filter, filterArgs, createSearchControls()); // revert environment change if (binaryAttributes != null && binaryAttributes.size() != 0) { if (binaryAttributesBackup == null) { context.removeFromEnvironment(ENV_BINARY_ATTRIBUTES); } else { context.addToEnvironment(ENV_BINARY_ATTRIBUTES, binaryAttributesBackup); } } if (pageSize != 0 && context instanceof LdapContext) { ((LdapContext)context).setRequestControls(controlsBackup); } return results; }
baseTmpRequestControls.add(new PagedResultsControl(pageSize, Control.NONCRITICAL)); tmpRequestControls.add(new PagedResultsControl(pageSize, cookie, Control.CRITICAL)); tmpRequestControls.add(new PagedResultsControl(pageSize, cookie, Control.CRITICAL));
if (pageSize > 0) { baseTmpRequestControls.add(new PagedResultsControl(pageSize, Control.NONCRITICAL)); if (pageSize > 0) { tmpRequestControls.add(new PagedResultsControl(pageSize, cookie, Control.CRITICAL)); if (pageSize > 0) { tmpRequestControls.add(new PagedResultsControl(pageSize, cookie, Control.CRITICAL));
new Control[] { new SortControl( getSortingAttributesKeys(), Control.NONCRITICAL ), new PagedResultsControl( GetPagingSize(), cookie, Control.CRITICAL ) } ); } else { getInitialContext().setRequestControls( new Control[] { new PagedResultsControl( GetPagingSize(), cookie, Control.CRITICAL ) } );
ctlp = new PagedResultsControl( GetPagingSize(), Control.CRITICAL ); nrCtl++; if ( log.isDebug() ) {
context.setRequestControls(new Control[]{new PagedResultsControl(pageSize, Control.NONCRITICAL)}); final List<LdapUser> users = new ArrayList<LdapUser>(); NamingEnumeration<SearchResult> results; s_logger.info("No controls were sent from the ldap server"); context.setRequestControls(new Control[] {new PagedResultsControl(pageSize, cookie, Control.CRITICAL)}); } while (cookie != null);
/** * Encodes the size and cookie values. */ private void encode() { try { controlValue = new PagedResultsControl( size, cookie, critical ).getEncodedValue(); } catch ( IOException e ) { } }
private List<SearchResult> pagedSearch(LdapContext ldapContext, String searchFilter) throws Exception { List<SearchResult> data = new ArrayList<>(); log.trace("Using paged ldap search, pageSize={}", pageSize); Control[] requestControls = new Control[]{new PagedResultsControl(pageSize, Control.CRITICAL)}; ldapContext.setRequestControls(requestControls); do { List<SearchResult> pageResult = simpleSearch(ldapContext, searchFilter); data.addAll(pageResult); log.trace("Page returned {} entries", pageResult.size()); } while (prepareNextPage(ldapContext)); if (log.isDebugEnabled()) { log.debug("Found a total of {} entries for ldap filter {}", data.size(), searchFilter); } return data; }
private boolean prepareNextPage(LdapContext ldapContext) throws Exception { Control[] responseControls = ldapContext.getResponseControls(); byte[] cookie = null; if (responseControls != null) { for (Control responseControl : responseControls) { if (responseControl instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl) responseControl; cookie = prrc.getCookie(); } } } if (cookie == null) { return false; } else { ldapContext.setRequestControls(new Control[]{new PagedResultsControl(pageSize, cookie, Control.CRITICAL)}); return true; } }
requestControls.add(new PagedResultsControl(controls.getPageSize(), cookie, Control.CRITICAL)); requestControls.add(new PagedResultsControl(controls.getPageSize(), Control.CRITICAL));
/** * Set the standard request controls */ private void setRequestControls(byte[] cookie) throws TranslatorException { List<Control> ctrl = new ArrayList<Control>(); SortKey[] keys = searchDetails.getSortKeys(); try { if (keys != null) { ctrl.add(new SortControl(keys, Control.NONCRITICAL)); } if (this.executionFactory.usePagination()) { ctrl.add(new PagedResultsControl(this.executionContext.getBatchSize(), cookie, Control.CRITICAL)); } if (!ctrl.isEmpty()) { this.ldapCtx.setRequestControls(ctrl.toArray(new Control[ctrl.size()])); LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Sort/pagination controls were created successfully."); //$NON-NLS-1$ } } catch (NamingException ne) { final String msg = LDAPPlugin.Util.getString("LDAPSyncQueryExecution.setControlsError") + //$NON-NLS-1$ " : "+ne.getExplanation(); //$NON-NLS-1$ throw new TranslatorException(ne, msg); } catch(IOException e) { throw new TranslatorException(e); } }
private NamingEnumeration<SearchResult> searchWithPagination() throws NamingException, IOException { Control[] controlsBackup = null; Object binaryAttributesBackup = null; // backup and set environment if (pageSize != 0 && context instanceof LdapContext) { controlsBackup = ((LdapContext)context).getRequestControls(); ((LdapContext)context).setRequestControls(new Control[]{ new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); } if (binaryAttributes != null && binaryAttributes.size() != 0) { // set attributes which should be returned in binary form binaryAttributesBackup = context.getEnvironment().get(ENV_BINARY_ATTRIBUTES); context.addToEnvironment(ENV_BINARY_ATTRIBUTES, String.join(" ", binaryAttributes)); } NamingEnumeration<SearchResult> results = context.search(new LdapName(searchDn), filter, filterArgs, createSearchControls()); // revert environment change if (binaryAttributes != null && binaryAttributes.size() != 0) { if (binaryAttributesBackup == null) { context.removeFromEnvironment(ENV_BINARY_ATTRIBUTES); } else { context.addToEnvironment(ENV_BINARY_ATTRIBUTES, binaryAttributesBackup); } } if (pageSize != 0 && context instanceof LdapContext) { ((LdapContext)context).setRequestControls(controlsBackup); } return results; }
private NamingEnumeration<SearchResult> searchWithPagination() throws NamingException, IOException { Control[] controlsBackup = null; Object binaryAttributesBackup = null; // backup and set environment if (pageSize != 0 && context instanceof LdapContext) { controlsBackup = ((LdapContext)context).getRequestControls(); ((LdapContext)context).setRequestControls(new Control[]{ new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); } if (binaryAttributes != null && binaryAttributes.size() != 0) { // set attributes which should be returned in binary form binaryAttributesBackup = context.getEnvironment().get(ENV_BINARY_ATTRIBUTES); context.addToEnvironment(ENV_BINARY_ATTRIBUTES, String.join(" ", binaryAttributes)); } NamingEnumeration<SearchResult> results = context.search(new LdapName(searchDn), filter, filterArgs, createSearchControls()); // revert environment change if (binaryAttributes != null && binaryAttributes.size() != 0) { if (binaryAttributesBackup == null) { context.removeFromEnvironment(ENV_BINARY_ATTRIBUTES); } else { context.addToEnvironment(ENV_BINARY_ATTRIBUTES, binaryAttributesBackup); } } if (pageSize != 0 && context instanceof LdapContext) { ((LdapContext)context).setRequestControls(controlsBackup); } return results; }
private NamingEnumeration<SearchResult> searchWithPagination() throws NamingException, IOException { Control[] controlsBackup = null; Object binaryAttributesBackup = null; // backup and set environment if (pageSize != 0 && context instanceof LdapContext) { controlsBackup = ((LdapContext)context).getRequestControls(); ((LdapContext)context).setRequestControls(new Control[]{ new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); } if (binaryAttributes != null && binaryAttributes.size() != 0) { // set attributes which should be returned in binary form binaryAttributesBackup = context.getEnvironment().get(ENV_BINARY_ATTRIBUTES); context.addToEnvironment(ENV_BINARY_ATTRIBUTES, String.join(" ", binaryAttributes)); } NamingEnumeration<SearchResult> results = context.search(new LdapName(searchDn), filter, filterArgs, createSearchControls()); // revert environment change if (binaryAttributes != null && binaryAttributes.size() != 0) { if (binaryAttributesBackup == null) { context.removeFromEnvironment(ENV_BINARY_ATTRIBUTES); } else { context.addToEnvironment(ENV_BINARY_ATTRIBUTES, binaryAttributesBackup); } } if (pageSize != 0 && context instanceof LdapContext) { ((LdapContext)context).setRequestControls(controlsBackup); } return results; }
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); if (paging) { ctx.setRequestControls(new Control[] { new PagedResultsControl(pageSize, true) }); ctx.setRequestControls(new Control[] { new PagedResultsControl(pageSize, cookie, true) });
@Override public List<SearchResult> execute(LdapContext context) throws NamingException { try { byte[] cookie = (byte[])identityQuery.getPaginationContext(); PagedResultsControl pagedControls = new PagedResultsControl(identityQuery.getLimit(), cookie, Control.CRITICAL); context.setRequestControls(new Control[] { pagedControls }); NamingEnumeration<SearchResult> search = context.search(baseDN, filter, cons); while (search.hasMoreElements()) { result.add(search.nextElement()); } search.close(); Control[] responseControls = context.getResponseControls(); if (responseControls != null) { for (Control respControl : responseControls) { if (respControl instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl)respControl; cookie = prrc.getCookie(); identityQuery.setPaginationContext(cookie); } } } return result; } catch (IOException ioe) { LDAP_STORE_LOGGER.errorf(ioe, "Could not query server with paginated query using DN [%s], filter [%s]", baseDN, filter); throw new NamingException(ioe.getMessage()); } } });
@Override public List<SearchResult> execute(LdapContext context) throws NamingException { try { byte[] cookie = (byte[])identityQuery.getPaginationContext(); PagedResultsControl pagedControls = new PagedResultsControl(identityQuery.getLimit(), cookie, Control.CRITICAL); context.setRequestControls(new Control[] { pagedControls }); NamingEnumeration<SearchResult> search = context.search(baseDN, filter, cons); while (search.hasMoreElements()) { result.add(search.nextElement()); } search.close(); Control[] responseControls = context.getResponseControls(); if (responseControls != null) { for (Control respControl : responseControls) { if (respControl instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl)respControl; cookie = prrc.getCookie(); identityQuery.setPaginationContext(cookie); } } } return result; } catch (IOException ioe) { LDAP_STORE_LOGGER.errorf(ioe, "Could not query server with paginated query using DN [%s], filter [%s]", baseDN, filter); throw new NamingException(ioe.getMessage()); } } });
new PagedResultsControl(LDAPUserRegistry.this.queryBatchSize, pagedResultsResponseControl == null ? null : pagedResultsResponseControl.getCookie(), Control.CRITICAL) });
new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); return true;
new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); return true;