Results 1 to 4 of 4

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

  1. #1
    Join Date
    Jul 2005
    Posts
    10

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

    I need to get the full DN of results returned by the ldapTemplate.search()

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

    Code:
    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:
    Code:
    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. #2
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    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.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  3. #3
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    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.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  4. #4
    Join Date
    Nov 2006
    Posts
    3

    Default 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •