简体   繁体   English

具有自定义属性的Java LDAP用户创建

[英]Java LDAP user creation with custom attribute

I am trying to create an LDAP user with a single custom attribute, but I am getting a 我正在尝试创建具有单个自定义属性的LDAP用户,但是却收到了一个

javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - 0000207D: UpdErr: DSID-0315166D, problem 6002 (OBJ_CLASS_VIOLATION), data -2131045114

When I remove the userId custom attribute from the code, it runs perfectly and so that i can create the user, but this custom attribute is used by a third party app and I should create it with this attribute for sure. 当我从代码中删除userId自定义属性时,它会正常运行,因此我可以创建用户,但是此自定义属性已由第三方应用程序使用,因此我肯定会使用此属性来创建它。

Can you give me any idea about what is going on with this attribute? 您能给我关于此属性发生什么的任何想法吗? What can be the problem? 可能是什么问题? Thanks 谢谢

Here is the code that i am getting the error: 这是我收到错误的代码:

Attributes container = new BasicAttributes();

        Attribute objClasses = new BasicAttribute("objectClass");
        objClasses.add("top");
        objClasses.add("person");
        objClasses.add("organizationalPerson");
        objClasses.add("user");

        this.cnValue = new StringBuffer(firstName).append(" ").append(lastName).toString();
        Attribute cn = new BasicAttribute("cn", cnValue);
        Attribute sAMAccountName = new BasicAttribute("sAMAccountName", userName);
        Attribute principalName = new BasicAttribute("userPrincipalName", userName + "@" + DOMAIN_NAME);
        Attribute givenName = new BasicAttribute("givenName", firstName);
        Attribute sn = new BasicAttribute("sn", lastName);
        Attribute uid = new BasicAttribute("uid", userName);
        Attribute sshPublicKey = new BasicAttribute("sshPublicKey", "AAAAAAAAAAAAAAAAAAAAAAAA");

        Attribute userPassword = new BasicAttribute("userpassword", password);

        container.put(objClasses);
        container.put(sAMAccountName);
        container.put(principalName);
        container.put(cn);
        container.put(sn);
        container.put(givenName);
        container.put(uid);
        container.put(userPassword);
        container.put(sshPublicKey);

        container.put("loginId", "aaa"); //When I remove this, user can be created successfully

        this.context.createSubcontext(getUserDN(cnValue, organisationUnit), container);

Assuming the schema has been modified for the "single custom attribute". 假设已针对“单个自定义属性”修改了架构。 (you do not cover that in the question), you probably need to create the user then add the custom attribute value AFTER the Add operation. (您不会在问题中解决),您可能需要创建用户,然后在“添加”操作之后添加自定义属性值。

除非您为其中一个objectClass -es修改了架构,否则需要添加extensibleObject对象类以使用自定义属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM