Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing Microsoft AD LDAP through JNDI

Makrand Pare
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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(
at com.sun.jndi.ldap.LdapCtx.processReturnCode(
at com.sun.jndi.ldap.LdapCtx.processReturnCode(
at com.sun.jndi.ldap.LdapCtx.c_lookup(
at com.sun.jndi.toolkit.ctx.ComponentContext.p_lookup(
at com.sun.jndi.toolkit.ctx.PartialCompositeContext.lookup(
at com.sun.jndi.toolkit.ctx.PartialCompositeContext.lookup(
at javax.naming.InitialContext.lookup(
at Lookup.main(

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

Hashtable<String, Object> env = new Hashtable<String, Object>(11);
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?

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic