Getting LDAP Response Controls : LdapContext « JNDI LDAP « Java






Getting LDAP Response Controls

 

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.HasControls;
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");

    LdapContext ctx = new InitialLdapContext(env, null);

    NamingEnumeration answer = ctx.search("ou=People", "(cn=*)", null);

    System.out.println(ctx.getResponseControls());

    while (answer.hasMore()) {
      SearchResult si = (SearchResult) answer.next();
      if (si instanceof HasControls) {
        System.out.println(((HasControls) si).getControls());
      }
    }
    System.out.println(ctx.getResponseControls());
  }
}

   
  








Related examples in the same category

1.how to look up an object
2.Setting LDAP Connection Request Controls
3.Setting LDAP Context Request Controls
4.Use Person class to add an entry to the LDAP server