Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

LDAP simple authontication Error

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I tried to connect to my company's LDAP server,but in 'none' Authonication SECURITY_PRINCIPAL it is throwing me error "in orader to perform this operation a successful bind must be completed on the connection"

but I dont know what String I should provide to SECURITY_PRINCIPAL when
SECURITY_AUTHENTICATION is simple.

I tried with "cn=abhsaxen" (my user name) but I am getting LDAP Error No 49.
Is there any way to get SECURITY_PRINCIPAL ??

Thanks in advance..
 
Author
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest you to look at ..how you created you Directory Context...for example.... Check your SECURITY_PRINCIPAL it should look like this !!! You may choose a different cn (Directory Manager is not recommended in production)

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389");
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,"cn=Directory Manager");
env.put(Context.SECURITY_CREDENTIALS,"password");
DirContext ctx = new InitialDirContext(env)



Then perform Context.bind for craeting or searching for user objects...for example to create user (which I picked from old code to create user in Sun Directory).

User MyUser = new User("jranch","Java","Rancher","ou=JavaGurus", "jranch@coresecuritypatterns.com");
ctx.bind("uid=jranch,ou=People,o=coresecuritypatterns.com", myUser);

I think, your code crashed during the bind operation....

To get SECURITY_PRINCIPAL in the code...for example in a Servlet, you may use HttpRequest.getUserPrincipal() method.

goodluck.
[ January 13, 2006: Message edited by: Ramesh Nagappan ]
 
Abhinit Saxena
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ramesh Nagappan:
I would suggest you to look at ..how you created you Directory Context...for example.... Check your SECURITY_PRINCIPAL it should look like this !!! You may choose a different cn (Directory Manager is not recommended in production)

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389");
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,"cn=Directory Manager");
env.put(Context.SECURITY_CREDENTIALS,"password");
DirContext ctx = new InitialDirContext(env)



Then perform Context.bind for craeting or searching for user objects...for example to create user (which I picked from old code to create user in Sun Directory).

User MyUser = new User("jranch","Java","Rancher","ou=JavaGurus", "jranch@coresecuritypatterns.com");
ctx.bind("uid=jranch,ou=People,o=coresecuritypatterns.com", myUser);

I think, your code crashed during the bind operation....

To get SECURITY_PRINCIPAL in the code...for example in a Servlet, you may use HttpRequest.getUserPrincipal() method.

goodluck.

[ January 13, 2006: Message edited by: Ramesh Nagappan ]




Hi Ramesh,

Thanks a lot for your help. But it is not working in my code. I used the same thing in my code

here is the code snipit


but I am passing query username and password from command prompt (for trial).

My main question is " Is there any way to get SECURITY_PRINCIPAL value from LDAP?". As per my understanding the value for SECURITY_PRINCIPAL should be in a specific format to get a successful bind.

Please correct me if I am wrong.

Thanks a lot once again.

Abhinit Saxena
 
Ramesh Nagappan
Author
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code looks perfect. There is a possibility the username (cn) you provided is not granted access to perform a search ! To test the code.. use "cn=Directory Manager" and its password. Your LDAP administrator should able to help here or if you have access to your LDAP console try search using the same username and see what happens.

-R
 
Abhinit Saxena
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a Tons,

It is start working...

 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! 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
reply
    Bookmark Topic Watch Topic
  • New Topic