[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

Add/Update to LDAP

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
osiruz
Asked:
osiruz
1 Solution
 
raid999Commented:
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
 
osiruzAuthor Commented:
thanks for the solution.
i will give that a try.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now