Solved

Add/Update to LDAP

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

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

15 Experts available now in Live!

Get 1:1 Help Now