Package javax.naming.ldap

Examples of javax.naming.ldap.PagedResultsControl


            // expected
        }
    }

    public void testReconnect() throws Exception {
        Control[] expected = new Control[] { new PagedResultsControl(10,
                Control.NONCRITICAL) };
        env.put("java.naming.ldap.control.connect", expected);

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        LdapContext context = new InitialLdapContext(env, null);

        Control[] controls = context.getConnectControls();
        assertNotNull(controls);
        assertNotSame(expected, controls);

        Control c = controls[0];
        assertTrue(c instanceof PagedResultsControl);
        assertEquals(Control.NONCRITICAL, ((PagedResultsControl) c)
                .isCritical());
        assertEquals(expected[0], c);

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

        expected = new Control[] { new SortControl("", Control.NONCRITICAL) };
        context.reconnect(expected);

        controls = context.getConnectControls();
        assertNotNull(controls);
        assertEquals(1, controls.length);
        c = controls[0];
        assertTrue(c instanceof SortControl);
        assertEquals(Control.NONCRITICAL, ((SortControl) c).isCritical());
        assertNotSame(expected, controls);
        assertEquals(expected[0], c);

        expected[0] = new PagedResultsControl(10, Control.NONCRITICAL);
        controls = context.getConnectControls();
        assertNotNull(controls);
        assertEquals(1, controls.length);
        c = controls[0];
        assertTrue(c instanceof SortControl);
View Full Code Here


        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

        assertEquals(referrals[0], ex.getReferralInfo());
        Context refContext = ex.getReferralContext(env, new Control[] {
                new PagedResultsControl(1, true),
                new SortControl("hello", true) });

        Hashtable<Object, Object> refEnv = (Hashtable<Object, Object>) refContext
                .getEnvironment();
View Full Code Here

  private void setControls(boolean deleted) {
    try {
      Control[] controls;
      if (deleted) {
        controls = new Control[] {
            new PagedResultsControl(1000, false), new DeletedControl()};
      } else {
        controls = new Control[] {
            new PagedResultsControl(1000, false)};
      }
      ldapContext.setRequestControls(controls);
    } catch (IOException e) {
      LOGGER.log(Level.WARNING, "Couldn't initialize LDAP paging control. "
        + "Will continue without paging - this can cause issue if there"
View Full Code Here

          if (resultResponseControls[i] instanceof
              PagedResultsResponseControl) {
            cookie = ((PagedResultsResponseControl) resultResponseControls[i])
                .getCookie();
            ldapContext.setRequestControls(new Control[] {
                new PagedResultsControl(1000, cookie, Control.CRITICAL)});
          }
        }
      } while ((cookie != null) && (cookie.length != 0));

      // if we received non complete attribute we need to use range based
View Full Code Here

      System.out.println("#################SEARCH BY QUERY FILTER##########################");
      SearchControls searchControls = new SearchControls();
      searchControls.setCountLimit(5);
      searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
      Control[] requestControls =
         {new PagedResultsControl(3, Control.CRITICAL), new SortControl(new String[]{"cn"}, Control.NONCRITICAL)};
      ctx.setRequestControls(requestControls);
      results = ctx.search(DEVELOPER_UNIT_DN, "(objectclass=person)", searchControls);
      while (results.hasMoreElements())
      {
         SearchResult sr = (SearchResult)results.nextElement();
View Full Code Here

    */
   @Override
  protected void populateCurrentPage(int page) throws Exception
   {
      List<User> users = new ArrayList<User>();
      PagedResultsControl prc = new PagedResultsControl(getPageSize(), Control.NONCRITICAL);
      String[] keys = {ldapAttrMapping.userUsernameAttr};
      SortControl sctl = new SortControl(keys, SEARCH_CONTROL);

      LdapContext ctx = ldapService.getLdapContext();
      try
      {
         NamingEnumeration<SearchResult> results = null;
         for (int err = 0;; err++)
         {
            users.clear();
            try
            {
               ctx.setRequestControls(new Control[]{sctl, prc});
               SearchControls constraints = new SearchControls();
               constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);

               byte[] cookie = null;
               int counter = 0;

               do
               {
                  counter++;
                  results = ctx.search(searchBase, filter, constraints);

                  while (results != null && results.hasMore())
                  {
                     SearchResult result = results.next();
                     if (counter == page)
                        users.add(ldapAttrMapping.attributesToUser(result.getAttributes()));
                  }

                  Control[] responseControls = ctx.getResponseControls();
                  if (responseControls != null)
                  {
                     for (int z = 0; z < responseControls.length; z++)
                     {
                        if (responseControls[z] instanceof PagedResultsResponseControl)
                           cookie = ((PagedResultsResponseControl)responseControls[z]).getCookie();
                     }
                  }
                  ctx
                     .setRequestControls(new Control[]{new PagedResultsControl(getPageSize(), cookie, Control.CRITICAL)});
               }
               while (cookie != null);
               this.currentListPage_ = users;
               return;
            }
View Full Code Here

     */
    private void encode()
    {
        try
        {
            controlValue = new PagedResultsControl( size, cookie, critical ).getEncodedValue();
        }
        catch ( IOException e )
        {
        }
    }
View Full Code Here

    * {@inheritDoc}
    */
   protected void populateCurrentPage(int page) throws Exception
   {
      List<User> users = new ArrayList<User>();
      PagedResultsControl prc = new PagedResultsControl(getPageSize(), Control.NONCRITICAL);
      String[] keys = {ldapAttrMapping.userUsernameAttr};
      SortControl sctl = new SortControl(keys, SEARCH_CONTROL);

      LdapContext ctx = ldapService.getLdapContext();
      try
      {
         NamingEnumeration<SearchResult> results = null;
         for (int err = 0;; err++)
         {
            users.clear();
            try
            {
               ctx.setRequestControls(new Control[]{sctl, prc});
               SearchControls constraints = new SearchControls();
               constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);

               byte[] cookie = null;
               int counter = 0;

               do
               {
                  counter++;
                  results = ctx.search(searchBase, filter, constraints);

                  while (results != null && results.hasMore())
                  {
                     SearchResult result = results.next();
                     if (counter == page)
                        users.add(ldapAttrMapping.attributesToUser(result.getAttributes()));
                  }

                  Control[] responseControls = ctx.getResponseControls();
                  if (responseControls != null)
                  {
                     for (int z = 0; z < responseControls.length; z++)
                     {
                        if (responseControls[z] instanceof PagedResultsResponseControl)
                           cookie = ((PagedResultsResponseControl)responseControls[z]).getCookie();
                     }
                  }
                  ctx
                     .setRequestControls(new Control[]{new PagedResultsControl(getPageSize(), cookie, Control.CRITICAL)});
               }
               while (cookie != null);
               this.currentListPage_ = users;
               return;
            }
View Full Code Here

    */
   @Override
   protected void populateCurrentPage(int page) throws Exception
   {
      List<User> users = new ArrayList<User>();
      PagedResultsControl prc = new PagedResultsControl(getPageSize(), Control.NONCRITICAL);
      String[] keys = {ldapAttrMapping.userUsernameAttr};
      SortControl sctl = new SortControl(keys, SEARCH_CONTROL);

      LdapContext ctx = ldapService.getLdapContext();
      try
      {
         NamingEnumeration<SearchResult> results = null;
         for (int err = 0;; err++)
         {
            users.clear();
            try
            {
               ctx.setRequestControls(new Control[]{sctl, prc});
               SearchControls constraints = new SearchControls();
               constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);

               byte[] cookie = null;
               int counter = 0;

               do
               {
                  counter++;
                  results = ctx.search(searchBase, filter, constraints);

                  while (results != null && results.hasMore())
                  {
                     SearchResult result = results.next();
                     if (counter == page)
                        users.add(ldapAttrMapping.attributesToUser(result.getAttributes()));
                  }

                  Control[] responseControls = ctx.getResponseControls();
                  if (responseControls != null)
                  {
                     for (int z = 0; z < responseControls.length; z++)
                     {
                        if (responseControls[z] instanceof PagedResultsResponseControl)
                           cookie = ((PagedResultsResponseControl)responseControls[z]).getCookie();
                     }
                  }
                  ctx.setRequestControls(new Control[]{new PagedResultsControl(getPageSize(), cookie, Control.CRITICAL)});
               }
               while (cookie != null);
               this.currentListPage_ = users;
               return;
            }
View Full Code Here

       

        /* User paged results to control page size. Some systems can have limited query size (for example Active Directory, which limits
         * results count to 1000. So we must use Range property to perform multiple search
         */
    PagedResultsControl pagedControls = new PagedResultsControl(500, Control.CRITICAL);
    context.setRequestControls(new Control[] {pagedControls});
   
    /* Cookie is used to inform server to send another page */
    byte[] cookie = null;
      int total = 0;

       
        /* Sum of all users imported from LDAP */
        int ldapUserCount = 0;
       
       
        do
        {
          /* Create search controls and apply range limit */
          SearchControls searchControls = createSearchControls(screenName, attributesToFetch);
          NamingEnumeration<SearchResult> enu = searchLdapUsers(context, companyId, ldapServerId, screenName, searchControls);
         
          /* There should be no exception here becouse we use paged searching */
            while (enu.hasMore())
            {
              ldapUserCount++;
                SearchResult result = enu.nextElement();
                Attributes attributes = result.getAttributes();
                String login = getAttributeValue(attributes, userMappingsScreenName, null);

                if (login != null)
                {
                  logger.info("Teta user login: "+login);
                    Properties userAttributes = propertiesMap.get(login);
                    if (userAttributes != null) {
                        for (String propertyName : customAttributes.stringPropertyNames()) {
                            String value = getAttributeValue(attributes, customAttributes.getProperty(propertyName), null);
                            logger.info("Teta user property="+propertyName+", value="+value);
                            if (value != null) {
                                userAttributes.setProperty(propertyName, value);
                            }
                        }
                    }
                    else
                    {
                       logger.info("Teta user userAttributes are empty for login="+login);
                    }

                }
            }
           
            /* Search response controls form paged results control */
            Control[] controls = context.getResponseControls();
            if (controls != null)
            {
                for (int i = 0; i < controls.length; i++)
                {
                    if (controls[i] instanceof PagedResultsResponseControl)
                    {
                        PagedResultsResponseControl prrc = (PagedResultsResponseControl)controls[i];
                        total = prrc.getResultSize();
                        cookie = prrc.getCookie();
                       
                        /* Update ldap context. In this moment, we inform server that it should
                         * send another page of results
                         *
                         * If cookie == null, there is no more results
                         */
                        pagedControls = new PagedResultsControl(500, cookie, Control.CRITICAL);
                    context.setRequestControls(new Control[] {pagedControls});
                    }
                }
            }
             
View Full Code Here

TOP

Related Classes of javax.naming.ldap.PagedResultsControl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.