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

    // Perform list() with controls in effect
    NamingEnumeration answer = ctx.list("");

    // Enumerate answers
    while (answer.hasMore()) {
        NameClassPair item = (NameClassPair);
} catch (NamingException e) {

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.