I'm not a JNDI expert, but here's a thought...are you able to create an entry of your new objectclass via any other means ?  For example, can you successfully create one by making an LDIF file and importing it with LDIFDE or ldapmodify ?  If so, then at least you know your schema definitions are OK and you can concentrate on your code.  If not, you'll have to look harder at your definition to make sure, for example, that that it's OK to put an object of that type into that OU, etc.  If you've already tried all that, then nevermind.
 
Dave
-----Original Message-----
From: Rafael Torres [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 16, 2003 6:33 AM
To: [EMAIL PROTECTED]
Subject: [ActiveDir] Problem: Using JNDI to add new entries

Hi there,
 
I'm building and JAVA application, using JNDI to store and retrive objects in LDAP.
I'm using Active Directory as the LDAP server and have modified the schema to match my needs.
 
Has a test, I have created a new objectClass using MMC console and the Active Directory Schema snap-in.
I called the new objectClass 'ee-teste' and set has it's mandatory attributes the attribute 'cn' and has it's optional atributes the 'mail' attribute.
 
I have an organizationalUnit with the DN=OU=EExtender,DC=eextender,DC=pt and I'm trying to create a new entry of type 'ee-teste', but keep getting a SchemaViolationException.
If I try to create a standard Active Directory object, like 'locality', my code works fine. But with my object it crashes.
Can anyone help me. I'm stuck here and can't see the solution.
 
Thx.
 
Here's the code I'm using:
 
 
String jndiURL = "ldap://192.168.65.199:389/";
  String initialContextFactory = "com.sun.jndi.ldap.LdapCtxFactory";
  String authenticationMode = "simple";
  String contextReferral = "ignore";
//  String securityProtocol = "ssl";
//  String principal = "cn=Directory Manager, ou=EExtender, dc=eextender, dc=pt";
  String principal = "
[EMAIL PROTECTED]";
  String credentials = "password";
  Hashtable env = new Hashtable();
  env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
  env.put(Context.PROVIDER_URL, jndiURL);
  env.put(Context.SECURITY_AUTHENTICATION, authenticationMode);
  env.put(Context.SECURITY_PRINCIPAL, principal);
  env.put(Context.SECURITY_CREDENTIALS, credentials);
  env.put(Context.REFERRAL, contextReferral);
//  env.put(Context.SECURITY_PROTOCOL, securityProtocol);
//  env.put("java.naming.ldap.factory.socket","javax.net.ssl.SSLSocketFactory");
  env.put("java.naming.ldap.version","3");
 

  DirContext ctx = null;
 

  try {
   ctx = new InitialDirContext(env);
 
   BasicAttributes attrs = new BasicAttributes();
 
   BasicAttribute ocs = new BasicAttribute("objectclass");
   ocs.add("ee-teste");
   attrs.put(ocs);
 
   BasicAttribute cn = new BasicAttribute("cn", "abrek");
   attrs.put(cn);
   BasicAttribute mail = new BasicAttribute( "mail", "
[EMAIL PROTECTED]" );
   attrs.put(mail);
 
   ctx.createSubcontext("cn=abrek,OU=EExtender,DC=eextender,DC=pt", attrs);
   ctx.close();
  } catch (NameAlreadyBoundException nex) {
   System.out.println("User ID is already in use, please select a different user ID ...");
  } catch (Exception ex) {
   System.out.println("Failed to create user account... Please verify the user information...");
   ex.printStackTrace();
  }
 
 
And the returned Exception:
 
javax.naming.directory.SchemaViolationException: [LDAP: error code 65 - 00002099: UpdErr: DSID-03050BA2, problem 6002 (OBJ_CLASS_VIOLATION), data 0
 
 
Rafael M. Torres ([EMAIL PROTECTED])
---------------------------------------------
Infopulse Portugal
Pr. dos Poveiros, 56, 2º
4000-393 Porto, Portugal
Tel: +351 223 389 103
Fax: +351 223 389 104
ICQ: 86290812

Reply via email to