List All Users from LDAP using JNDI

We  have already seen the fundamentals of JNDI  along with examples for Naming as well as Directory Services using JNDI. So far, all the  JNDI examples using LDAP were fetching/updating a particular user from the DIT. In this section we would list all the users from LDAP using JNDI in “ou=users,ou=system” in a generic way.

List All Users from LDAP using JNDI

The basic setup is same as that of the previous examples.We are using Apache Directory Studio as the LDAP provider .In this case we are searching the users details using the search() method of DirContext object.

ldap

DirectorySample.java

 

The code shown here lists all the attributes of all users.This can be controlled by adding returning attributes to search controls .

Example:

String[] attributes = { “cn”, “employeeNumber”, “sn” };
searchCtrls.setReturningAttributes(attributes);

JNDI Overview

JNDI example – Naming Service

JNDI example -Directory Service 

One thought on “List All Users from LDAP using JNDI

  1. SACHIN NANA BHOJANE says:

    Not able to get all user. Its able to pull only 1000 records.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">