| Author |
LDAP Connection.
|
Naresh Daswani
Greenhorn
Joined: Mar 02, 2006
Posts: 19
|
|
HI , I'm using the following code to make connection with ldap ... Hashtable env=new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL,"LDAP://HDDLGSDGTH4034"); env.put(Context.REFERRAL,"ignore"); env.put(Context.SECURITY_AUTHENTICATION,"simple"); env.put(Context.SECURITY_PRINCIPAL,"cn=Administrator"); env.put(Context.SECURITY_CREDENTIALS,"HCLTech123"); DirContext ctx=new InitialDirContext(env); System.out.println("ur context is ready"); //Object obj=ctx.lookup("nareshd@hcl.in"); //System.out.println("ur context is looked up " + obj); SearchControls constraints=new SearchControls(); constraints.setSearchScope(SearchControls.SUBTREE_SCOPE); String attrs[] = {"cn", "givenName", "userPrincipalName"}; constraints.setReturningAttributes(attrs); String filter = "(cn=A*)"; String BASE_SEARCH="ou=people,dc=HCLGGN.LOCAL,dc=com"; System.out.println("going to search your name"); NamingEnumeration answer = ctx.search(BASE_SEARCH, 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 ldap...as 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
Greenhorn
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!!
|
 |
 |
|
|
subject: LDAP Connection.
|
|
|