How do I add a self defined attribute for an ldap user?
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);
Attribute created successfully, Now I am trying to add this attribute so that the user says "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 an object class violation error.
Can anyone help me solve this problem? I need to add a custom attribute for a user using java code.
a source to share
You create an attribute, then select the class it should belong to and update the class.
You can change the base class (comes with the base LDAP server schema), the efficient class (an object class that can exist on its own, such as inetOrgPerson), or a helper class (cannot make an object of this type, but it extends another object class).
So, define an aux class to "hold" your new attribute, then add an entry to your target's object class with your class name, and then you can add that attribute to the user.
We do this all the time.
a source to share