gpt4 book ai didi

java - 我们可以使用 Java 在 openLDAP 中为域组件条目创建子上下文吗?

转载 作者:行者123 更新时间:2023-12-01 09:56:45 24 4
gpt4 key购买 nike

我正在尝试为域组件创建子上下文,但它显示以下错误

javax.naming.OperationNotSupportedException:[LDAP:错误代码 53 - 没有全局高级知识];剩余名称 'uid=user3, dc=example'

这是我的代码

公共(public)类 OpenLDAPTest {

public static void main(String[] args) {
String url = "ldap://localhost:389";
// String url = "ldap://localhost:10389";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Manager,dc=maxcrc,dc=com");
// env.put(Context.SECURITY_PRINCIPAL, "uid=admin, ou=system");
env.put(Context.SECURITY_CREDENTIALS, "secret");
try {
DirContext ctx = new InitialDirContext(env);
System.out.println("connected");
System.out.println(ctx.getEnvironment());
System.out.println("Creating subContext");
String name = "uid=user3, dc=example";
Attributes atrs = new BasicAttributes();
Attribute atr1 = new BasicAttribute("objectClass");
atr1.add("inetOrgPerson");
atrs.put(atr1);
Attribute atr2 = new BasicAttribute("cn");
atr2.add("sathish");
atrs.put(atr2);
Attribute atr3 = new BasicAttribute("o");
atr3.add("Kumar");
atrs.put(atr3);
Attribute atr4 = new BasicAttribute("sn");
atr4.add("example");
atrs.put(atr4);
Context c = ctx.createSubcontext(name, atrs);
System.out.println(c.getEnvironment());
ctx.close();

} catch (AuthenticationNotSupportedException ex) {
System.out
.println("The authentication is not supported by the server");
} catch (AuthenticationException ex) {
System.out.println("incorrect password or username");
} catch (NamingException ex) {
// System.out.println("error when trying to create the context");
ex.printStackTrace();
}
}

}

如果我对 ApacheDS 使用相同的代码(通过更改凭据)它的工作。但它不适用于 openLDAP。

最佳答案

您可以尝试安装时将域名设置为“dc=example”

在LDAP后端设置步骤中,

ldap setting
(来源:userbooster.de)

否则您可以将“uid=user3, dc=example”更改为“uid=user3,dc=maxcrc,dc=com”来添加它。

当 Windows 服务器中已经存在根目录为“dc=maxrc,dc=com”的数据库时,不必费心添加根目录为“dc=example”的数据库。

更新:

虽然您将域名设置为“dc=maxcrc,dc=com”,但默认情况下不会添加相应的域名根条目。

在添加该子上下文之前,您需要添加“dc=maxcrc,dc=com”

    String name = "dc=maxcrc,dc=com";
Attributes atrs = new BasicAttributes();
Attribute atr1 = new BasicAttribute("objectClass");
atr1.add("organization");
atrs.put(atr1);
Attribute atr2 = new BasicAttribute("objectClass");
atr2.add("dcObject");
atrs.put(atr2);
Attribute atr3 = new BasicAttribute("dc");
atr3.add("maxcrm");
atrs.put(atr3);
Attribute atr4 = new BasicAttribute("o");
atr4.add("anyOrgYouLike");
atrs.put(atr4);
Context c = ctx.createSubcontext(name, atrs);

关于java - 我们可以使用 Java 在 openLDAP 中为域组件条目创建子上下文吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37160842/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com