我正在尝试为域组件创建子上下文, 但它显示以下错误
javax.naming.OperationNotSupportedException:[LDAP:错误代码53 - 没有全球优势知识];剩余名称'uid = user3,dc = example'
这是我的代码
公共类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。
答案 0 :(得分:1)
您可以尝试将域名设置为' dc = example'安装时
在LDAP后端设置步骤中,
否则你可以改变" uid = user3,dc = example"到" uid = user3,dc = maxcrc,dc = com" 来添加它。
不要为自己添加一个带有root" dc = example"的数据库而烦恼。虽然已经存在一个带有root" dc = maxrc,dc = com"在Windows服务器中。
<强>更新强>
虽然您将域设置为&#34; dc = maxcrc,dc = com&#34;但默认情况下不会添加相应的域根条目。
您需要添加&#34; dc = maxcrc,dc = com&#34;在添加该子上下文之前
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);
答案 1 :(得分:0)
您尝试的内容相当于在OpenLDAP中创建名为dc=example
的新数据库。您只能通过配置来实现。