javax.naming.directory.SchemaViolationException:[LDAP:错误代码65 - 对象类违规];

时间:2015-05-13 15:58:36

标签: java active-directory ldap

在此代码中,我无法将一个用户添加到组中。这里uid是用户。这里cn = citizen,cn = doit,o = evault是group 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", "sai@xx.com");
        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);

此处显示错误:

javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - Object Class Violation]; remaining name 'uid=datta,cn=doit,o=evault'

1 个答案:

答案 0 :(得分:0)

对于您是将用户,群组,组织还是用户添加到群组,您似乎完全感到困惑。

当前问题是groupOfNames不会扩展organization,或反之亦然,它们都是STRUCTURAL对象类,因此您无法同时指定它们在同一个对象中。这是一种架构违规,就像消息所说的那样。

注意:您无需将BasicAttribute投射到Attribute.