Announcement Announcement Module
No announcement yet.
Support for multiple base in contextSource Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Support for multiple base in contextSource

    I can successfully obtain and read Person attributes from Active Directory when using a simple spring beans configuration. However, I need to support searching multiple base DN's and it doesnt appear contextSource bean properties can support multiple DN base's like urls? When I attempt to instantiate LdapContextSource myself Im getting the following trace:

    at .getAnonymousEnv(
    at urce.getReadOnlyContext( :106)

    Here is the code Im using:

    DefaultDirObjectFactory factory = new DefaultDirObjectFactory();
    LdapContextSource contextSource = new LdapContextSource();
    contextSource.setBase("DN path");
    contextSource.setUrls(new String[] {"ldap url"});
    contextSource.setDirObjectFactory(factory.getClass ());


    Anybody ever use LdapTemplate to search multiple DN paths?

  • #2
    The base path is optional - you may leave it out to have all your operations originate att the very root of the LDAP tree.


    • #3
      Thanks for the response. I commented out the base property in the spring-beans file, and replaced with adding with the following code:

      DistinguishedName name = new DistinguishedName();
      name.add("OU=path,OU=tomyusers,DC=foo,DC=bar,DC=co m");
      catch(InvalidNameException e)
      // TODO Auto-generated catch block

      EqualsFilter filter = new EqualsFilter(
      "objectclass", "person");
      name, filter
      .encode(), getContextMapper());

      But Im getting the following LDAP Naming exception:
      org.springframework.ldap.UncategorizedLdapExceptio n: Operation failed; nested exception is javax.naming.NamingException: [LDAP: error code 1 - 000020D6: SvcErr: DSID-03100684, problem 5012 (DIR_ERROR), data 0

      Basically Im attempting to search for users/person in AD from multiple DN locations. Any ideas what I can do from there?



      • #4
        I don't know exactly what the Active Directory error message means, but one problem I find in your code is that you're not creating the DistinguishedName correctly. DistinguishedName.add() takes a single RDN component and adds it to the DistinguishedName. Try doing DistinguishedName name=new DistinguishedName("OU=path,OU=...."); instead. Whether this will fix your problem is another question, but at least we're one step closer to tracking it down.

        You can also send the actual DN string as the first parameter to the search, rather than a parsed DistinguishedName.

        Also, when using ContextSource outside of a Spring ApplicationContext, make sure that you call afterPropertiesSet() once you're finished setting all your properties (That's probably what caused the NullPointerException in your first example)


        • #5
          Thanks Much, rasky!

          afterPropertiesSet() solution really helped me to overcome NPE.

          I was also coding similar to robert.heise.

          Thanks again for the posts.