Solved

LDAP Query

Posted on 2002-06-03
6
1,893 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

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…
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

691 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