Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active Directory Service access?

Status
Not open for further replies.

BabyJeffy

Programmer
Sep 10, 2003
4,189
GB
I've been asked to look into writing a phone book lookup (ie: read-only) web application using Apache Tomcat 4.1 (on Win32). The U/I requirements are not a problem, and I am fairly adept at crafting my JSP code... but I'm stuck.

As I understand it, I will need to talk to the Active Directory Services on our Windows network from within my web application.

I've looked high and low but I can't find details (or examples) for anything like this.

Is there anyone out there that could offer me some advice/direction on this?

Thanks in advance,
Jeff
 
Thanks for that venur...

I'm now well along the road to a working solution.

For those of you interested, I started with some taglibs and managed to code up a page that returned a sample of what I wanted. Problems with being unable to pass dynamic data into the taglib parameters has now dragged me away form that idea (for those interested, I was using easyldap taglibs from simya).

Now I have a much better understanding of LDAP and exactly what it can do/be used for. I'm not a particularly strong Java developer, but I can usually impliment things (given enough samples etc)... but we all learn from the exercise.

I'm now going to try using the JBBC-LDAP bridge developed by Octetstring (
I'll keep you informed!

Jeff
 
-Jeffy,

It really nice that you are on a working solution. It would be nice if you can write up a little document on how to configure the OpenLDAP and how to establish the communication between Tomcat Server and OpenLDAP server. As I am really intrested to run couple of examples using LDAP and tomcat. Never worked on it.

Best Of Luck.

Thank you.
Venu
 
Just to keep you up to date, I'm settling in for some LDAP work over the next couple of days. The following URL is to be my starting point regarding the actual Java code I'll be using.


For anyone following in my footsteps, the highest hurdle was trying to understand the layout of the LDAP schema being used (onsite with the Active Directory Services in place). Then it was trying to understand how to form the LDAP queries. And then being unsure whether the problem being experienced was connectivity related or just bad syntax.

I found the following Java application (compiled for Windows) incredibly valuable. I'm not running a particularly fast computer here, but it works fine and provided me with a reliable test harness for my queries and investigation.


I'll keep the thread active as I reach a conclusion.

Jeff
 
Hi,

Maybe you can help me with this problem.
I am writing a JSP Application and need to have a login form. I want to leverage the accounts that are already created in our Active Directory. Can this be done? Is there any good examples I can follow?

Thanks
VC
 
This will look up entries for someone in active directory /ldap server :

Code:
import javax.naming.directory.*;
import javax.naming.*;
import java.util.*;

public class ActDir {

	public static void main(String args[]) throws Exception {



		Hashtable env = new Hashtable();
		DirContext ctx;

		String port = args[1];
		String host = args[0];
		String user = "corp\\aaaaa";
		String passwd = "bbbb";

		env.put(Context.SECURITY_AUTHENTICATION,"simple");
		env.put(Context.SECURITY_PRINCIPAL, user);
		env.put(Context.SECURITY_CREDENTIALS, passwd);

		//env.put("java.naming.ldap.version", "3");
		//env.put(Context.REFERRAL, "follow");

		String url = new String("ldap://"+host+":"+port);
		env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
		env.put(Context.PROVIDER_URL,url);

		System.err.println("Connecting to " +url);
		ctx = new InitialDirContext(env);

		//ctx.bind(user, ctx, null);

		System.err.println("Connected to " +url);

		// Read supportedSASLMechanisms from root DSE
		Attributes attrs = ctx.getAttributes(url,new String[]{"supportedSASLMechanisms"});
		System.err.println(attrs);

		Attributes answer = ctx.getAttributes("OU=People,OU=Exeter,DC=corp,DC=acme,DC=net");

		// Specify the attributes to match
		// Ask for objects that has a surname ("sn") attribute with
		// the value "Geisel" and the "mail" attribute
		Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
		matchAttrs.put(new BasicAttribute("sn", "Geisel"));
		matchAttrs.put(new BasicAttribute("mail"));

		// Search for objects that have those matching attributes
		NamingEnumeration ne = ctx.search("OU=People,OU=Exeter,DC=corp,DC=acme,DC=net", matchAttrs);

		while (ne.hasMoreElements()) {
			System.out.println(ne.next());
		}


	ctx.close();
	}
}

There is also a good tutorial on ldap at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top