Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Accessing Microsoft AD LDAP through JNDI

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to lookup some names in Microsoft AD LDAP server. I'm using JNDI APIs to connect and lookup names from that LDAP server.
I'm successfully able to make a connection to the LDAP server however while looking up the name it gives me the following exception:

Lookup failed: javax.naming.NamingException: [LDAP: error code 1 - 000020D6: Svc
Err: DSID-031006CC, problem 5012 (DIR_ERROR), data 0 ]; remaining name 'cn=parema'
javax.naming.NamingException: [LDAP: error code 1 - 000020D6: SvcErr: DSID-03100
6CC, problem 5012 (DIR_ERROR), data 0
]; remaining name 'cn=parema'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3025)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2931)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2737)
at com.sun.jndi.ldap.LdapCtx.c_lookup(LdapCtx.java:993)
at com.sun.jndi.toolkit.ctx.ComponentContext.p_lookup(ComponentContext.java:526)
at com.sun.jndi.toolkit.ctx.PartialCompositeContext.lookup(PartialCompositeContext.java:159)
at com.sun.jndi.toolkit.ctx.PartialCompositeContext.lookup(PartialCompositeContext.java:148)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at Lookup.main(Lookup.java:61)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I'm using the following code to connect to the LDAP:

Hashtable<String, Object> env = new Hashtable<String, Object>(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "LDAP://CORP.WEYER.PRI";);
env.put(Context.SECURITY_PRINCIPAL, "parema@CORP");
env.put(Context.SECURITY_CREDENTIALS, "mycorppassword!");

Context ctx = new InitialContext(env);
// Perform lookup and cast to target type
LdapContext b = (LdapContext) ctx.lookup("cn=parema");

I'm sure that I'm able to connect to the LDAP server as I'm using my corp username and password to connect to it. In case I use any other username and password, it gives me an javax.naming.AuthenticationException.

Please let me know if this is the right way to lookup values from an LDAP server?

Thanks,
Makrand
 
I child proofed my house but they still get in. Distract them with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic