Announcement Announcement Module
No announcement yet.
Modifying LDAP Context's Base? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Modifying LDAP Context's Base?

    I am successfully able to create an LDAP context from my Spring xml file, and would like to modify the base attribute of the context. My base is pointing to the highest point in my LDAP tree, and I would like to add objects at points deeper in the tree (additional levels in the tree already exist). Example:

    base: ou=Test,dc=example,dc=com
    exists: ou=Users,ou=Test,dc=example,dc=com
    looking to add: uid=admin,ou=Users,ou=Test,dc=example,dc=com

    Unfortunately if I try to add the last entry above with the current base, the operation will fail saying that ou=Users already exists. As such, I'd like to change the base for the context to ou=Users,ou=Test,dc=example,dc=com so that the add will succeed. I have tried the following, without much luck:
    ctx.setBase("ou=Users," + ctx.getReadOnlyContext().getNameInNamespace());
    Here is the bulk of the code:
    FileSystemResource in =
    			new FileSystemResource("spring-ldapContext.xml");
    		BeanFactory factory =
    			new XmlBeanFactory(in);
    		LdapTemplate ldapTemplate = null;
            try {
            	LdapContextSource ctx = (LdapContextSource)factory.getBean("contextSource");
            	String base = "ou=Users," + ctx.getReadOnlyContext().getNameInNamespace();
                ldapTemplate = new LdapTemplate(ctx);
            catch (NamingException e) {
    Any help would be greatly appreciated!

    Kevin Hardiman

  • #2
    There should be no need to modify the base of the ContextSource to be able to add entries. I suspect the problem is in the code that attempts to add the sub-entry (uid=admin,ou=Users,ou=Test,dc=example,dc=com). If you'll post that code along with the stack trace, I'll be happy to take a look at it.


    • #3
      Problem Solved

      You were correct - there was a problem elsewhere. I created a DistinguishedName, added the RDNs from the base including the OUs that already existed, and finally the object to be added with success.
           DistinguishedName dn = new DistinguishedName();
           dn.add("ou", "Users");
           dn.add("uid", u.getUserId());