Use Person class to add an entry to the LDAP server : LdapContext « JNDI LDAP « Java

Use Person class to add an entry to the LDAP server


import java.util.Hashtable;

import javax.naming.Context;

public class Main {
  public static String INITCTX = "com.sun.jndi.ldap.LdapCtxFactory";

  public static String MY_HOST = "ldap://localhost:389";

  public static String MGR_DN = "uid=yourid, ou=People,";

  public static String MGR_PW = "password";

  public static String MY_SEARCHBASE = "";

  public static void main(String args[]) throws Exception {
    Hashtable<String, String> env = new Hashtable<String, String>();

    env.put(Context.PROVIDER_URL, MY_HOST);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, MGR_DN);
    env.put(Context.SECURITY_CREDENTIALS, MGR_PW);

    DirContext ctx = new InitialDirContext(env);

    Person p = new Person();
    ctx.bind("uid=mewilcox, ou=People,", p);

class Person{
  String name="name";


Related examples in the same category to look up an object
2.Setting LDAP Connection Request Controls
3.Setting LDAP Context Request Controls
4.Getting LDAP Response Controls