Solved

LDAP Query

Posted on 2002-06-03
6
1,888 Views
Last Modified: 2010-05-18
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 !!!
0
Comment
Question by:Jitu
6 Comments
 
LVL 7

Expert Comment

by:HalldorG
ID: 7065623
There are some modules in perl that I have been using
They work well.
0
 
LVL 1

Expert Comment

by:raid999
ID: 7077720
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
 
LVL 54

Expert Comment

by:nico5038
ID: 7265841

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 1

Author Comment

by:Jitu
ID: 7266587
No suitable answer received. Request the administrator to remove this question if that is alright.
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7266758
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
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7296599
Per recommendation, points NOT refunded and question closed.

Netminder
CS Moderator
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now