How to add an self defined attribute to ldap user?

Posted by Arnab Das on Stack Overflow See other posts from Stack Overflow or by Arnab Das
Published on 2010-05-07T10:27:31Z Indexed on 2010/05/07 10:38 UTC
Read the original article Hit count: 283

Filed under:
|

Hi, I have created an attribute in LDAP using the following code.

attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.1.9"); attrs.put("NAME", "myattribute"); attrs.put("DESC", "for JNDITutorial example only"); attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.15"); DirContext schema = context.getSchema(""); DirContext newAttr = schema.createSubcontext ("AttributeDefinition/myattribute1", attrs);

The attribute is created successfully, Now I am trying to add this attribute to a user say "user1"(uid).

Attributes attributeslist = context.getAttributes(ld.getUserDN(username)); attributeslist.put("myattribute1", ""); context.modifyAttributes(ld.getUserDN("test5"), DirContext.REPLACE_ATTRIBUTE, attributeslist);

But it gives me object class violation error.

Can anyone help me to solve this? I need to add an user defined attribut to the user using java code.

© Stack Overflow or respective owner

Related posts about ldap

Related posts about java