File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes LDAP Connection. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "LDAP Connection." Watch "LDAP Connection." New topic

LDAP Connection.

Naresh Daswani

Joined: Mar 02, 2006
Posts: 19
HI ,

I'm using the following code to make connection with ldap ...

Hashtable env=new Hashtable();

DirContext ctx=new InitialDirContext(env);

System.out.println("ur context is ready");
//Object obj=ctx.lookup("");
//System.out.println("ur context is looked up " + obj);
SearchControls constraints=new SearchControls();
String attrs[] = {"cn", "givenName", "userPrincipalName"};
String filter = "(cn=A*)";

String BASE_SEARCH="ou=people,dc=HCLGGN.LOCAL,dc=com";

System.out.println("going to search your name");

NamingEnumeration answer =, filter, constraints);
System.out.println("ur search has been performed");

//Object obj=ctx.lookup("naresh");

but I'm not able to make it up...can anyone tell me what is the problem with the code...and also plz tell me what all things should be in I do not have any Idea of it..
It is giving exception:
Exception is javax.naming.NamingException: [LDAP: error code 1 - 00000000
rr: DSID-0C090627, comment: In order to perform this operation a successful
bind must be completed on the connection., data 0, vece ]; remaining name ''
Mattias Arthursson
Ranch Hand

Joined: Jul 26, 2004
Posts: 90
It looks fine at a quick glance. The error message basically means that you need an authenticated context to perform your search. Since Principal and Credentials are supplied (which should normally result in an authenticated Context) in the environment, this leads me to think that either of them is incorrect (i.e. invalid login).

One would expect to get an error message when creating the DirContext instance, but Active Directory has been known to be less than friendly when it comes to error messages.

Admit nothing. Blame everyone. Be bitter.
Naresh Daswani

Joined: Mar 02, 2006
Posts: 19
Thanks Maddias,

U are right ... there was some problem in my login credentials... I have corrected it and now it is working...thanx for ur reply..

Naresh Daswani
Believe in UrSelf!!
I agree. Here's the link:
subject: LDAP Connection.
It's not a secret anymore!