Announcement Announcement Module
No announcement yet.
No easy way to get the full DN of search results? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • No easy way to get the full DN of search results?

    I need to get the full DN of results returned by the

    The easiest way I found of doing this was to use a NameClassPairCallbackHandler with code like this:

    public void handleNameClassPair(NameClassPair nameClassPair) {
            SearchResult result = (SearchResult)nameClassPair;
            String fullDn = result.getNameInNamespace();
    But getNameInNamespace() was not added to the API until Java 5, and I am constrained to use Java 1.4.

    So I have resorted to using a ContextMapper like this:
    public Object mapFromContext(Object object) {
            DirContextAdapter searchResultContext = (DirContextAdapter)object;
            String dn = searchResultContext.getNameInNamespace();
            // but this is relative to the base DN, so:
            if(baseDN.length() > 0) {
                    dn += "," + baseDN;
    I'm not sure if it was the intention for DirContextAdapter's getNameInNamespace() to return DNs relative to the base, but this is inconsistent with Java 5's getNameInNamespace() behavior. Maybe this is an implementation error in the Spring LDAP API?

    What's bothersome about my ContextMapper solution is I can't get the baseDN from either the ldapTemplate or even the ldapContextSource. So I have to expose a baseDN property on any beans that do LDAP searches, just so I can construct the full DN properly.

    Maybe I'm just missing something in the Spring LDAP API? Is there a better way to get full DN? If not, can this be made easier in a future release?

  • #2
    The base DN is intentionally removed from the DN of an entry when constructing a DirContextAdapter. This is so that the DN will be useful directly in LDAP operations - using the full DN when doing e.g. a modifyAttributes() wouldn't work. That said, the current implementation of getNameInNamespace() really could be considered a bug - that method should return the full DN, and then the getDn() method could return the 'stripped' DN.

    The simplest workaround I can think of at the moment would be to create your own implementation of DirObjectFactory - it's in DefaultDirObjectFactory the base path is removed.


    • #3
      Its in subversion now, so if you'd like to have it right away you could check it out from there and build it manually.


      • #4
        problem with full dn

        I am trying to use the function you describe before but I am not able to obtain the full dn. How do you do the search operation?

        Thank you.