khardiman
Feb 26th, 2007, 05:18 PM
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();
ctx.setBase(base);
ldapTemplate = new LdapTemplate(ctx);
}
catch (NamingException e) {
System.err.println(e.getMessage());
System.exit(1);
}
Any help would be greatly appreciated!
Kevin Hardiman
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();
ctx.setBase(base);
ldapTemplate = new LdapTemplate(ctx);
}
catch (NamingException e) {
System.err.println(e.getMessage());
System.exit(1);
}
Any help would be greatly appreciated!
Kevin Hardiman