java javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - Object Class Violation];
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30219907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - Object Class Violation];
提问by Abhishek Mahapatra
Here in this code, I am not able to add one user to group. Here uid is user. Here cn=citizens,cn=doit,o=evault is group Full DN and also instead of member I tried with memberOf. But still it is showing same Exception.
在此代码中,我无法将一个用户添加到组中。这里 uid 是用户。这里 cn=citizens,cn=doit,o=evault 是组 Full DN,也不是我尝试使用 memberOf 的成员。但它仍然显示相同的异常。
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, initctx);
env.put(Context.PROVIDER_URL, myhost);
env.put(Context.SECURITY_PRINCIPAL, mgrdn);
env.put(Context.SECURITY_CREDENTIALS, mgrpw);
System.out.println("Connect");
String entryDN = "uid=datta,cn=doit,o=evault";
// entry's attributes
BasicAttribute cn = new BasicAttribute("cn", "datta");
BasicAttribute sn = new BasicAttribute("sn", "kumar");
BasicAttribute mail = new BasicAttribute("mail", "[email protected]");
BasicAttribute phone = new BasicAttribute("telephoneNumber", "9704763492");
BasicAttribute uid = new BasicAttribute("uid", "datta");
BasicAttribute member = new BasicAttribute("member", "cn=citizens,cn=doit,o=evault");
BasicAttribute oc = new BasicAttribute("objectClass");
oc.add("top");
//oc.add("person");
oc.add("groupOfNames");
((javax.naming.directory.Attribute) oc).add("organization");
// ((javax.naming.directory.Attribute) oc).add("inetOrgPerson");
((javax.naming.directory.Attribute) oc).add("groupOfNames");
DirContext ctx = new InitialDirContext(env);
// build the entry
BasicAttributes entry = new BasicAttributes();
entry.put(cn);
entry.put(sn);
entry.put(mail);
entry.put(phone);
entry.put(uid);
entry.put(member);
entry.put(oc);
// Add the entry
ctx.createSubcontext(entryDN, (javax.naming.directory.Attributes) entry);
Here It showing error as :
这里它显示错误为:
javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - Object Class Violation]; remaining name 'uid=datta,cn=doit,o=evault'
回答by user207421
You seem to be totally confused as to whether you're adding a user, a group, an organization, or a user to a group.
您似乎对是添加用户、组、组织还是用户到组感到完全困惑。
The immediate problem is that groupOfNames
doesn't extend organization
, or vice versa,and they are both STRUCTURAL object classes, so you can't specify them both in the same object. It is a schema violation, just like the message says.
直接的问题是groupOfNames
不扩展organization
,反之亦然,并且它们都是 STRUCTURAL 对象类,因此您不能在同一个对象中同时指定它们。正如消息所说,这是架构违规。
NB You don't need to cast BasicAttribute
to Attribute.
注意你不需要投射BasicAttribute
到Attribute.