Hi, I am very new to LDAP and JNDI. Basically i would like to add a new OU into LDAP from JNDI. My LDAP server is setup from OpenDS.
Here's my code:
public static void main(String args[])
{
String INITCTX = "com.sun.jndi.ldap.LdapCtxFactory";
String MY_HOST = "ldap://localhost:1389";
String MGR_DN = "cn=Directory Manager";
String MGR_PW = "password";
String MY_SEARCHBASE = "dc=QuizPortal";
try
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX);
env.put(Context.PROVIDER_URL, MY_HOST);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, MGR_DN);
env.put(Context.SECURITY_CREDENTIALS, MGR_PW);
DirContext ctx = new InitialDirContext(env);
Attributes attrs = new BasicAttributes(true); // case-ignore
Attribute objclass = new BasicAttribute("objectclass");
objclass.add("top");
objclass.add("organizationalUnit");
attrs.put(objclass);
ctx.createSubcontext("ou=NewOu", attrs);
}
catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
Here's the error message:
javax.naming.NameNotFoundException: [LDAP: error code 32 - The provided entry ou=NewOu cannot be added because it does not have a parent and is not defined as one of the suffixes within the Directory Server]; remaining name 'ou=NewOu'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3066)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2987)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2794)
at com.sun.jndi.ldap.LdapCtx.c_createSubcontext(LdapCtx.java:788)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_createSubcontext(ComponentDirContext.java:319)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(PartialCompositeDirContext.java:248)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(PartialCompositeDirContext.java:236)
at javax.naming.directory.InitialDirContext.createSubcontext(InitialDirContext.java:178)
at JUNDIAdd2.main(JUNDIAdd2.java:43)
Addition info, i have o=IT, dc=QuizPortal where i want to add in the new OU.
Could anyone guide me around this error?? Any help will be greatly appreciated. Thanks!
Kevin