Solved

LDAP Query

Posted on 2002-06-03
6
1,886 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
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…

708 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

20 Experts available now in Live!

Get 1:1 Help Now