[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

How to integret JAVA for LDAP autentication?

We are having one internal application developed on JAVA. Now we want to Integrate autentication with existing windows 2003 Active directory. Is it possible to have ldap configured for authentication?
0
ktwoisg
Asked:
ktwoisg
  • 2
1 Solution
 
rameshsukkaCommented:
We have open source LDAP API avaiable in market. You can use these API as Action Directory is V3 protocol. For more clarity,

Programatically you need to Bind to LDAP server with proper credentials. Let me know if you required any help on this.

Regards,
Ramesh Sukka.
0
 
MeritorCommented:
If you just need authentication from LDAP, there is a simpler way to it.
Just use JNDI. if you are able to create context then the user is authenticated, otherwise not
	Hashtable env = new Hashtable();
	env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
	env.put(Context.PROVIDER_URL, "ldap://ap.abc.com:389");//LDAP server location
	env.put(Context.SECURITY_AUTHENTICATION,"simple");
	env.put(Context.SECURITY_PRINCIPAL,"userName"); // specify the username
	env.put(Context.SECURITY_CREDENTIALS,"password"); // specify the password
	DirContext ctx = new InitialDirContext(env);
 
	System.out.println("CTX:"+ctx);

Open in new window

0
 
ktwoisgAuthor Commented:
Please let me know how to Bind to LDAP server with proper credentials.
0
 
rameshsukkaCommented:

look at the sample code from
http://java.sun.com/products/jndi/tutorial/ldap/security/ldap.html

// Set up the environment for creating the initial context
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");

// Authenticate as S. User and password "mysecret"
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial");
env.put(Context.SECURITY_CREDENTIALS, "mysecret");

// Create the initial context
DirContext ctx = new InitialDirContext(env);

// ... do something useful with ctx


In above code,
S. user and password is "mysecret". After initializing content call ctx.bind() function

Regards,
Ramesh Sukka,
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now