Announcement Announcement Module
Collapse
No announcement yet.
Support for multiple base in contextSource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    java.lang.NullPointerException
    at org.springframework.ldap.support.LdapContextSource .getAnonymousEnv(LdapContextSource.java:48)
    at org.springframework.ldap.support.AbstractContextSo urce.getReadOnlyContext(AbstractContextSource.java :106)
    at org.springframework.ldap.LdapTemplate.search(LdapT emplate.java:263)

    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.setUserName("username");
    contextSource.setPassword("password");
    contextSource.setDirObjectFactory(factory.getClass ());

    ldapTemplate.setContextSource(contextSource);

    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.

    Comment


    • #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();
      try
      {
      name.add("OU=path,OU=tomyusers,DC=foo,DC=bar,DC=co m");
      name.
      }
      catch(InvalidNameException e)
      {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }

      EqualsFilter filter = new EqualsFilter(
      "objectclass", "person");
      return ldapTemplate.search(
      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?

      Thanks

      Comment


      • #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)

        Comment


        • #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.

          Comment

          Working...
          X