[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
InvalidNameException...[Invalid DN]
Hi All,
I installed OpenLDAP and am trying to access slapd server using JNDI.
I was able to add entries using an entries.ldif file and slapadd.
Now, I am trying to add using JNDI. following is an example pgm taken from
this mailing list.
which I have modified according to my values.
AddUser.java
----------------
/*
* Copyright (c) 1998. Sun Microsystems. All rights reserved.
*/
import java.util.Hashtable;
import java.util.Date;
import javax.naming.*;
import javax.naming.directory.*;
class AddUser {
public static void main(String[] args) {
Hashtable env = new Hashtable(5, 0.75f);
/*
* Specify the initial context implementation to use.
* This could also be set by using the -D option to the java program.
* For example,
* java -Djava.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory
* AddUser
*/
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
// host and port to use for directory service
env.put(Context.PROVIDER_URL, "ldap://localhost:389");
// authentication information
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "secret");
env.put(Context.SECURITY_CREDENTIALS, "secret");
// entry's DN
String entryDN = "cn=NewUser, dc=example, dc=com";
// entry's attributes
Attribute cn = new BasicAttribute("cn", "NewUser");
Attribute sn = new BasicAttribute("sn", "Smith");
Attribute mail = new BasicAttribute("mail", "newuser@foo.com");
Attribute phone = new BasicAttribute("telephoneNumber", "+1 222 333
4444");
Attribute uid = new BasicAttribute("uid", "nsmith");
Attribute userPassword = new BasicAttribute("userPassword", "pwd1");
Attribute oc = new BasicAttribute("objectClass");
oc.add("dcObject");
oc.add("person");
oc.add("inetOrgPerson");
DirContext ctx = null;
try {
// get a handle to an Initial DirContext
ctx = new InitialDirContext(env);
// build the entry
Attributes entry = new BasicAttributes();
entry.put(cn);
entry.put(sn);
entry.put(mail);
entry.put(phone);
entry.put(uid);
entry.put(userPasword);
entry.put(oc);
// Add the entry
ctx.createSubcontext(entryDN, entry);
System.out.println( "AddUser: added entry " + entryDN + ".");
} catch (NamingException e) {
System.err.println("AddUser: error adding entry." + e);
}
}
}
***********It gives me : javax.naming.InvalidNameException: [LDAP: error
code 34 - invalid DN]
These are the same Objectclasses that I used in my entries.ldif file and
slapadd enters the values correctly when i do:
>slapadd -l c:/entries.ldif -f c:/debug/slapd.conf -d -1
entries.ldif
-------------
dn: dc=example, dc=com
dc: example
objectClass: dcObject
dn: cn=james clark, dc=example, dc=com
objectClass:person
cn: james
sn: clark
telephoneNumber: 123-456-789
userPassword: werq
objectClass: inetOrgPerson
mail: james.clark@ajh.com
uid: jclark
and it did insert the values...
Can anyone please help me out???
thanks in advance.
Susmitha.
---------------------------
Susmitha Vuyyuru
Developer
<mailto:susmitha.vuyyuru@portalwave.com>
1.650.314.0936
Portal Wave, Inc.
The Fastest Track to Integrated e-Business
www.portalwave.com