Setting LDAP Connection Request Controls : LdapContext « JNDI LDAP « Java

Setting LDAP Connection Request Controls


import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.ldap.Control;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;

public class Main {
  public static void main(String[] argv) throws Exception {
    String url = "ldap://localhost/o=JNDITutorial";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "userDN");
    env.put(Context.SECURITY_CREDENTIALS, "secret");
    // Create connection controls to use
    Control[] connectCtls = new Control[] { null };

    LdapContext ctx = new InitialLdapContext(env, connectCtls);


Related examples in the same category to look up an object
2.Setting LDAP Context Request Controls
3.Getting LDAP Response Controls
4.Use Person class to add an entry to the LDAP server