Example usage for javax.naming.ldap PagedResultsControl PagedResultsControl

List of usage examples for javax.naming.ldap PagedResultsControl PagedResultsControl

Introduction

In this page you can find the example usage for javax.naming.ldap PagedResultsControl PagedResultsControl.

Prototype

public PagedResultsControl(int pageSize, byte[] cookie, boolean criticality) throws IOException 

Source Link

Document

Constructs a control to set the number of entries to be returned per page of results.

Usage

From source file:com.adito.activedirectory.PagedResultTemplate.java

private void applyControls(InitialLdapContext context, int pageSize, byte[] cookie) throws NamingException {
    try {//from   www . j  a v a  2 s.  c om
        context.setRequestControls(
                new Control[] { new PagedResultsControl(pageSize, cookie, Control.CRITICAL) });
    } catch (IOException ex) {
        logger.warn("Tried to reconfigure paged result controls with error", ex);
    }
}

From source file:de.acosix.alfresco.mtsupport.repo.auth.ldap.LDAPInitialDirContextFactoryImpl.java

/**
 * {@inheritDoc}/*from  w  w w . ja  v a  2  s.  c  om*/
 */
@Override
// copied from default Alfresco class
public boolean hasNextPage(final DirContext ctx, final int pageSize) {
    if (pageSize > 0) {
        try {
            final LdapContext ldapContext = (LdapContext) ctx;
            final Control[] controls = ldapContext.getResponseControls();

            // Retrieve the paged result cookie if there is one
            if (controls != null) {
                for (final Control control : controls) {
                    if (control instanceof PagedResultsResponseControl) {
                        final byte[] cookie = ((PagedResultsResponseControl) control).getCookie();
                        if (cookie != null) {
                            // Prepare for next page
                            ldapContext.setRequestControls(new Control[] {
                                    new PagedResultsControl(pageSize, cookie, Control.CRITICAL) });
                            return true;
                        }
                    }
                }
            }
        } catch (final NamingException nx) {
            throw new AuthenticationException("Unable to connect to LDAP Server; check LDAP configuration", nx);
        } catch (final IOException e) {
            throw new AuthenticationException(
                    "Unable to encode LDAP v3 request controls; check LDAP configuration", e);
        }

    }
    return false;
}

From source file:org.alfresco.repo.security.authentication.ldap.LDAPInitialDirContextFactoryImpl.java

public boolean hasNextPage(DirContext ctx, int pageSize) {
    if (pageSize > 0) {
        try {/*w  w w  .  j  a v  a2  s  . co  m*/
            LdapContext ldapContext = (LdapContext) ctx;
            Control[] controls = ldapContext.getResponseControls();

            // Retrieve the paged result cookie if there is one
            if (controls != null) {
                for (Control control : controls) {
                    if (control instanceof PagedResultsResponseControl) {
                        byte[] cookie = ((PagedResultsResponseControl) control).getCookie();
                        if (cookie != null) {
                            // Prepare for next page
                            ldapContext.setRequestControls(new Control[] {
                                    new PagedResultsControl(pageSize, cookie, Control.CRITICAL) });
                            return true;
                        }
                    }
                }
            }
        } catch (NamingException nx) {
            throw new AuthenticationException("Unable to connect to LDAP Server; check LDAP configuration", nx);
        } catch (IOException e) {
            throw new AuthenticationException(
                    "Unable to encode LDAP v3 request controls; check LDAP configuration", e);
        }

    }
    return false;
}

From source file:org.olat.ldap.LDAPLoginManagerImpl.java

private byte[] getCookie(final LdapContext ctx) throws NamingException, IOException {
    byte[] cookie = null;
    // Examine the paged results control response
    final Control[] controls = ctx.getResponseControls();
    if (controls != null) {
        for (int i = 0; i < controls.length; i++) {
            if (controls[i] instanceof PagedResultsResponseControl) {
                final PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i];
                cookie = prrc.getCookie();
            }/*from  w w w.j av a  2  s.  co m*/
        }
    }
    // Re-activate paged results
    ctx.setRequestControls(new Control[] { new PagedResultsControl(PAGE_SIZE, cookie, Control.CRITICAL) });
    return cookie;
}