Je voudrais ajouter un nouveau OU
dans LDAP de JNDI. Mon serveur LDAP est configuré à partir d'OpenDS.Comment ajouter OU dans LDAP en utilisant JNDI
Voici mon 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);
}
}
Voici le message d'erreur:
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)
info Addition: Je o=IT, dc=QuizPortal
où je veux ajouter dans la nouvelle OU
.
Quelqu'un peut-il me guider autour de cette erreur?
Hey MERCI .. qui fonctionne comme un charme. Pour le bénéfice des autres, avec la réponse de Perry et j'ai édité MY_HOST = "ldap: // localhost: 1389/dc = QuizPortal", je peux ajouter le nouveauOu sous o = IT ... – Nivek