Solved

Add/Update to LDAP

Posted on 2002-05-02
2
173 Views
Last Modified: 2010-03-31
Hi

Does anyone knows where can i find information/sample codes on how to connect to an LDAP server and how to add and update the entries?

thanks and regards.
0
Comment
Question by:osiruz
[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
2 Comments
 
LVL 1

Accepted Solution

by:
raid999 earned 50 total points
ID: 6988240
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
 

Author Comment

by:osiruz
ID: 6990935
thanks for the solution.
i will give that a try.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

734 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