【发布时间】:2010-08-10 09:21:48
【问题描述】:
我想从 JNDI 向 LDAP 添加一个新的 OU。我的 LDAP 服务器是从 OpenDS 设置的。
这是我的代码:
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);
}
}
这是错误信息:
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)
添加信息:我有o=IT, dc=QuizPortal,我想在其中添加新的OU。
谁能指导我解决这个错误?
【问题讨论】: