Adding LDAP Entries Using JNDI

I am trying to add an entry to an LDAP server using JNDI. I could successfully read the entries from the LDAP server. But when I try to add a new record, I get errors. I checked different ways, but could not.

private String getUserAttribs (String searchAttribValue) throws NamingException{ SearchControls ctls = new SearchControls(); ctls.setSearchScope(SearchControls.OBJECT_SCOPE); Attributes matchAttrs = new BasicAttributes(true); matchAttrs.put(new BasicAttribute("uid", searchAttribValue)); NamingEnumeration answer = ctx.search("ou=People,ou=ABCLdapRealm,dc=abcdomain",matchAttrs); SearchResult item =(SearchResult) answer.next(); // uid userpassword description objectclass wlsmemberof sn cn return item.toString(); } 

This worked correctly.

Then I took a step forward and tried to add a record. The code is as follows.

  public static void bindEntry(DirContext dirContext)throws Exception{ Attributes matchAttrs = new BasicAttributes(true); // uid userpassword description objectclass wlsmemberof sn cn matchAttrs.put(new BasicAttribute("uid", "defaultuser")); matchAttrs.put(new BasicAttribute("userpassword", "password")); matchAttrs.put(new BasicAttribute("description", "defaultuser")); matchAttrs.put(new BasicAttribute("cn", "defaultuser")); matchAttrs.put(new BasicAttribute("sn", "defaultuser")); matchAttrs.put(new BasicAttribute("objectclass", "top")); matchAttrs.put(new BasicAttribute("objectclass", "person")); matchAttrs.put(new BasicAttribute("objectclass", "organizationalPerson")); matchAttrs.put(new BasicAttribute("objectclass","inetorgperson")); matchAttrs.put(new BasicAttribute("objectclass", "wlsUser")); String name="uid=defaultuser"; InitialDirContext iniDirContext = (InitialDirContext)dirContext; iniDirContext.bind(name,dirContext,matchAttrs); } 

But with that, I get an exception.

 Exception in thread "main" javax.naming.OperationNotSupportedException: [LDAP: error code 53 - Unwilling To Perform]; remaining name 'uid=defaultuser' 

I'm definitely breaking something. Any idea on this?

+4
source share
3 answers

LDAP 53, not wanting to perform, usually means what it says. You tried to make something "illegal" in terms of LDAP servers.

First, are you unlikely to point to eDirectory? If this is the case, adding sn is important, as the eDirectory schema must specify the Surname value at creation time. In this case, you will probably get a slightly different error, more similar to error 608 or 611.

Secondly, you point to Active Directory, in which case fullName is a required attribute. But in this case, you also usually get a small result code. There must be more mistakes. (Although it may be a return of JNDI compared to the tools that I also use).

Thirdly, you point to some server of the LDAP server, and you missed the required attribute in the schema.

Actually, perhaps this is an object class problem. Is wlsUser a helper class or a real class? Is inetorgperson a real (I confuse the name for this type of class, is there an additional, structural and something else) class in your directory?

My main assumption: you missed the required attribute and break the scheme in your target directory, and I hope that possible examples of the missing required directions mentioned above are useful.

+4
source

This is an error that occurs when trying to set a password in Active Directory using a non-SSL connection. Try again without the password string.

+2
source

Hi, using the code below, I can insert a person into ldap from jndi program

 Attributes attributes=new BasicAttributes(); Attribute objectClass=new BasicAttribute("objectClass"); objectClass.add("inetOrgPerson"); attributes.put(objectClass); Attribute sn=new BasicAttribute("sn"); Attribute cn=new BasicAttribute("cn"); sn.add("sahul"); cn.add("vetcha"); attributes.put(sn); attributes.put(cn); attributes.put("title","software engg") ctx.createSubcontext("uid=sahul,ou=some organization7,o=some company7,ou=system",attributes); 
+2
source

All Articles