Sorting and filtering LDAP data



Introduction

Lightweight Directory Access Protocol is a mapping between the names of resources in a network and their respective network addresses. It is a shared information infrastructure for locating, managing, administering and organizing everyday items and network resources, which can include volumes, folders, files, printers, users, groups, devices, telephone numbers and other objects. A directory service is a critical component of a network operating system. A directory server or name server is a server which provides such a service. Each resource on the network is considered an object by the directory server. Information about a particular resource is stored as a collection of attributes associated with that resource or object.is a directory content and update requests. LDIF conveys directory content as a set of records, one record for each object (or entry). It also represents update requests, such as Add, Modify, Delete, and Rename, as a set of records, one record for each update request. The code below shows how to access and list Data from an LDAP server:

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) {
}

 

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.