I use this code snippets to add user to ldap
**public DirContext getLDAPDirContext() throws NamingException {
final Hashtable envValues = new Hashtable();
// Assign the JNDI environment values in Map
envValues.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
envValues.put(Context.PROVIDER_URL, url);
envValues.put(Context.SECURITY_PRINCIPAL,dn); // specify the username
envValues.put(Context.SECURITY_CREDENTIALS,password); // specify the password
return new InitialDirContext(envValues);
}
public static void main(String arg[]) throws NamingException {
LdapNew ldapNew = new LdapNew();
String groupDN ="ou=user,dc=ldap,dc=***,dc=***";
BasicAttributes myAttrs = new BasicAttributes(true); //Basic Attributes
myAttrs.put("uid","chamils");
myAttrs.put("objectClass","top");
myAttrs.put("objectClass","dcObject");
myAttrs.put("objectClass","organization");
myAttrs.put("objectClass", "inetOrgPerson");
myAttrs.put("cn","FNAME LNAME");
myAttrs.put("displayname", "FNAME LNAMEE");
myAttrs.put("givenname","Chamilseeee");
myAttrs.put("sn","Thanthrimudaliged");
myAttrs.put("mail","*******");
DirContext ctx = ldapNew.getLDAPDirContext();
ctx.bind("uid=chamils,ou=user,dc=ldap,dc=****,dc=***",myAttrs);
}**
But it gives
Exception in thread "main" javax.naming.directory.InvalidAttributeIdentifierException: [LDAP: error code 17 - javaSerializedData: attribute type undefined]; remaining name 'uid=chamils,ou=user,dc=ldap,dc=,dc=' at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3110) at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2987) at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2794) at com.sun.jndi.ldap.LdapCtx.c_bind(LdapCtx.java:397) at com.sun.jndi.ldap.LdapCtx.c_bind(LdapCtx.java:354) at com.sun.jndi.toolkit.ctx.ComponentContext.p_bind(ComponentContext.java:596) at com.sun.jndi.toolkit.ctx.PartialCompositeContext.bind(PartialCompositeContext.java:183) at com.sun.jndi.toolkit.ctx.PartialCompositeContext.bind(PartialCompositeContext.java:173) at javax.naming.InitialContext.bind(InitialContext.java:400) at LdapNew.main(LdapNew.java:49) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Why is that.