Solved

Add/Update to LDAP

Posted on 2002-05-02
2
174 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

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