• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

LDAP Connection.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ''
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Naresh Daswani
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic