You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pete Serafin <ps...@igneite.com> on 2002/10/11 16:26:49 UTC

OT: LDAP user add help

I am having some problems creating user accounts in my Struts 
application.  I am trying to create accounts on an iPlanet 5.1 LDAP 
server and keep getting a SchemaViolationError.  I have also in previous 
cases used the ldap admin dn and password when getting the inital 
context,  but get the same errors.The code is as follows:

try {
         //Hashtable for environmental information
        Hashtable env = new Hashtable(11);
        env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://localhost:389");

         //Get a reference to a directory context
         DirContext ctx = new InitialDirContext(env);

  Attributes myAttrs = new BasicAttributes(true);
  Attribute oc = new BasicAttribute("objectclass");
  oc.add("inetOrgPerson");
  oc.add("organizationalPerson");
  oc.add("person");
  oc.add("top");
  String cn = givenname+" "+sn;
  myAttrs.put(oc);
  //have also tried myAttrs.put("objectClass", oc);
  myAttrs.put("uid",uid);
  myAttrs.put("cn",cn);
  myAttrs.put("sn",sn);

  ctx.bind("uid=tuser,o=myserver.com", myAttrs);
  ctx.close();
}catch(Exception e){}


The error I keep getting from console is:


Create failed: javax.naming.directory.SchemaViolationError;
remaining name 'uid=tuser,o=myserver.com'
javax.naming.directory.InvalidAttributeValueException:
SchemaViolationError; remaining name 'uid=tuser,o=myserver.com'
        at
com.sun.jndi.ldap.LdapClient.encodeAttribute(LdapClient.java:974)
        at
com.sun.jndi.ldap.LdapClient.add(LdapClient.java:1022)
        at
com.sun.jndi.ldap.LdapCtx.c_bind(LdapCtx.java:351)
        at
com.sun.jndi.toolkit.ctx.ComponentDirContext.p_bind(ComponentDirConte
xt.java:277)


The server error I receive states that the cn is a required field.  When 
I change the dn to look like "cn=tuser,o=myserver.com" a 
javaContainer object is succesfully created.  Apparently my objectclass 
is being set or something.  Any ideas? Any help is greatly appreciated.