Solved

Add/Update to LDAP

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How  can  i  resolve  HTTP Status 404 -? 8 46
Which non-HTML GUI front end to use with Java? 3 24
Setup GlassFish 4 22
passing enum to a method 4 24
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

821 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