jeudi 26 février 2015

Adding LDAP entry using JNDI



I am trying to add LDAP entries in an already existing LDAP directory. Every LDAP entry has a set of attributes which I can change by using the following



Attributes attr = (Attributes) ctx.getAttributes("cn=somecn,ou=something1,ou=something2,ou=something3,o=something.com");

NamingEnumeration<?> nm = attr.getAll();
nm.next();

Attribute at = (Attribute) nm.next();
at.set(3, "testing");
attr.put(at);

ctx.bind("cn=somecn2,ou=something1,ou=something2,ou=something3,o=something.com",
null, attr);


This is like a clone with only the attributes changed. This adds the LDAP entry without any problems.


But I want to create an LDAP entry from scratch using ctx.bind


I tried to add objectclass attributes like



at.put("objectclass","top")
at.put("objectclass","javaContainer")


etc. but it throws this error : javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - Object Class Violation];


Please tell me where I can construct the object class. And add the attributes with index numbers too. I could not find a good LDAP object creating material or LDAP Java tutorial anywhere in google which explains clearly . Also please explain how to construct the objectClass values and add entries on my own instead of taking an already existing object and making the necessary changes.




Aucun commentaire:

Enregistrer un commentaire