LDAP Query

Hello

i am new to LDAP. And we are using openLDAP. I have never written any code to access data from LDAP.
Neither am i sure whether i must use JNDI or JLDAP(from Novell) to pick data from openLDAP.

I have to write a LDAP Query Engine. The functionality is simple. Display onw a web page a set of attributes (available in LDAP) for the user to choose from. Based on attributes the user selected i generate a Query to fetch data for those attributes from LDAP and display them to the user in the form of a report.

I am not sure how to do this. Can anyone give me example code or suggest how to go about doing this.

I only know what entries(objects) and their attributes are present in LDAP.

I am sure in many cases the user choice of attributes too would be invalid i.e it would not make sense to generate query for attributes from two totally unrelated objects etc...

Help !!!
LVL 1
JituAsked:
Who is Participating?
 
NetminderConnect With a Mentor Commented:
Per recommendation, points NOT refunded and question closed.

Netminder
CS Moderator
0
 
HalldorGCommented:
There are some modules in perl that I have been using
They work well.
0
 
raid999Commented:
Lookup.java provides access to LDAP

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

public class Lookup {
 public static void main(String args[]) {
   String name = "";
   if ( args.length > 0 ) name = args[0];
   try {
     Hashtable env = new Hashtable();
     env.put("java.naming.factory.initial",
             "com.sun.jndi.ldap.LdapCtxFactory");
     env.put("java.naming.provider.url",
             "ldap://ldap.nameflow.net:1389/");

     DirContext ictx = new InitialDirContext(env);
     Attributes a = ictx.getAttributes(name);
     NamingEnumeration all = a.getAll();
     while ( all.hasMore() ) {
       Attribute attr = (Attribute)all.next();
       System.out.println("Attribute: " + attr.getID());
       NamingEnumeration values = attr.getAll();
       while ( values.hasMore() )
         System.out.println("Value: " + values.next());
     }
   } catch ( Exception e ) {
     System.out.println("Exception: " + e);
   }
 }
}

Compiling and running this Java requires the following libraries

1-jndi.jar
2-ldap.jar
3-providerutil.jar

How to use the lookup.java

unix% java Lookup "ldap://ldap.nameflow.net:1389/cn=Dai Davies,o=DANTE,c=GB"
Attribute: collectiveTelephoneNumber
Value: +44 1223 302992
Attribute: organizationalStatus
Value: General Manager
Attribute: sn
Value: Davies
Attribute: collectivePostalAddress
Value: DANTE $ Francis House $ 112 Hills Road $ Cambridge $ CB2 1PQ $ United Kingdom
Attribute: collectiveStreetAddress
Value: 112 Hills Road
Attribute: mail
Value: Dai.Davies@dante.org.uk
...
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
nico5038Commented:

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
 - PAQ'd and pts removed
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 
JituAuthor Commented:
No suitable answer received. Request the administrator to remove this question if that is alright.
0
 
nico5038Commented:
Hi Jitu,

Glad you returned, I just missed a comment on the comments given by the two experts. Normally solving a Q is a "co-production" between questionner and expert(s)...

Nic;o)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.