Java examples for JNDI:LDAP
Setting LDAP Context Request Controls
import javax.naming.NameClassPair; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.naming.ldap.Control; import javax.naming.ldap.InitialLdapContext; import javax.naming.ldap.LdapContext; import javax.naming.ldap.SortControl; public class Main { public void main(String[] argv) { try { LdapContext ctx = new InitialLdapContext(env, null); // Create critical Sort that sorts based on CN Control[] ctxCtls = new Control[] { new SortControl( new String[] { "cn" }, Control.CRITICAL) }; // Sets context request controls; effect until unset ctx.setRequestControls(ctxCtls); // Perform list() with controls in effect NamingEnumeration answer = ctx.list(""); // Enumerate answers while (answer.hasMore()) { NameClassPair item = (NameClassPair) answer.next(); } } catch (NamingException e) { } } }