Announcement Announcement Module
No announcement yet.
LDAP range Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • LDAP range

    Hi, i am a new member,and i need to know if are posible use in the class LdapTemplate the method search,for find some users into a range. I read that exists an parameters.
    My code is similar like this

    List<Usuario> u ="", "(objectclass=user)",new LdapEntryMapper());

    That i need is get de user into de range.
    I wanna know if are posible put something like range = 0-*


  • #2
    This sounds a lot like what LDAP Matching Rules are about. This is a quote from section 4.5 in RFC 2252:

    Matching rules are used by servers to compare attribute values
    against assertion values when performing Search and Compare
    operations. They are also used to identify the value to be added or
    deleted when modifying entries, and are used when comparing a
    purported distinguished name with the name of an entry.

    Most of the attributes given in this document will have an equality
    matching rule defined.
    So, you see that "equality" is just something that happens to be the default. You can write your own rules and use them in searches.

    Spring LDAP does not yet have built-in support for matching rules, although we have discussed whether that could be a useful addition to the library. In the meantime, however, you could perhaps write your own conditional collecting handler. Here is my crude attempt of a generic class and an implementation that limits a search of 1000 numbers to the range 0-9.

    First the generic conditional collecting handler, where we add another abstract method and make the list add conditional of the return value of that method:

       private abstract static class ConditionalCollectingNameClassPairCallbackHandler
             extends CollectingNameClassPairCallbackHandler {
          public void handleNameClassPair(NameClassPair nameClassPair) {
             if (isValid(getObjectFromNameClassPair(nameClassPair))) {
          protected abstract boolean isValid(Object objectFromNameClassPair);
    Then we create an implementation of the standard method for getting the object, and also the condition method:

          CollectingNameClassPairCallbackHandler handler = 
                new ConditionalCollectingNameClassPairCallbackHandler() {
             protected boolean isValid(Object objectFromNameClassPair) {
                int value = Integer.parseInt((String) objectFromNameClassPair);
                if (value >= 0 && value < 10) {
                   return true;
                return false;
             public Object getObjectFromNameClassPair(NameClassPair nameClassPair) {
                SearchResult searchResult = (SearchResult) nameClassPair;
                try {
                   return searchResult.getAttributes().get("description").get();
                catch (NamingException e) {
                   throw LdapUtils.convertLdapException(e);
    The search then simply becomes:

, FILTER_STRING, searchControls, handler);
    Finally, here is the assertion that verifies that we only got the first ten values:

          List result = handler.getList();
          assertEquals(10, result.size());