有人使用 Active Directory 轻量级目录服务吗?我需要帮助。我编写了一个代码,但无法通过 java 在 Active Directory 中创建用户。
我所做的第一件事是,我通过 AD 编辑窗口在 AD LDS 服务器中手动创建了一个用户。我可以通过下面的程序连接它。
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, LDAP_URL);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "CN=testuser,OU=Gulf,DC=serviceProj");
env.put(Context.SECURITY_CREDENTIALS, "1234567");
env.put(Context.SECURITY_PROTOCOL, "ssl");
try {
DirContext ctx = new InitialDirContext(env);
}
我在 AD LDS 中手动创建了这个测试用户。现在我想使用java创建用户,我写了下面的代码,但是出错了。
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, LDAP_URL);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "CN=Admin,OU=Gulf,DC=serviceProj");//Admin- this is a admin user through which i login to this server machine on which ad LDA is installed, this same user was selected at time of creation of instance.
env.put(Context.SECURITY_CREDENTIALS, "1234567");
env.put(Context.SECURITY_PROTOCOL, "ssl");
try {
DirContext ctx = new InitialDirContext(env);
Attributes attrs = new BasicAttributes(true);
Attribute oc = new BasicAttribute("objectclass");
oc.add("top");
oc.add("person");
oc.add("organizationalPerson");
oc.add("user");
attrs.put(oc);
attrs.put(new BasicAttribute("cn", "testuser2"));
attrs.put(new BasicAttribute("name","test"));
ctx.createSubcontext("CN=testuser2,OU=Gulf,DC=serviceProj", attrs);
ctx.close();
}
我得到的错误-
[9/18/18 14:16:31:193 GST] 0000024c SystemErr R javax.naming.AuthenticationException: [LDAP: error code 49 - 8009030C: LdapErr: DSID-0C09042F, comment: AcceptSecurityContext error, data 2030, v2580
在这里,我在这一行得到错误 DirContext ctx = new InitialDirContext(env); 意味着我无法通过管理员用户连接。现在我需要帮助我需要连接哪个用户才能在那里创建用户?//Admin- 这是一个管理员用户,我通过它登录到托管广告 LDA 的服务器机器,在创建实例时选择了相同的用户。
我的代码有什么问题。请帮助我做任何事情,示例代码,视频任何东西