简体   繁体   中英

All Users from in LDAP in JAVA

i want to fetch all active Users from an LDAP. The LDAP has way over 1k Users (afaik you can only take 1k Users from Ldap in one request). When using C# i used this:

//Open connection to LDAP Server

using (var directoryEntry = new DirectoryEntry("LDAP"****************",
            {
                using (var directorySearcher = new DirectorySearcher(directoryEntry)
                {
                    PageSize = 1000,
                    Filter = "****************",
                    SearchScope = System.DirectoryServices.SearchScope.Subtree,
                    PropertiesToLoad =
                    {
                       ***,
                       ***,
                       ...
                    }
                })
                {
                    using (SearchResultCollection src = directorySearcher.FindAll())
                    {
                        try
                        {
                            foreach (SearchResult sr in src)
                            {
                                //Create User and add to a List of Users

Now i have to do the same but in Java code. What i tried is this:

NamingEnumeration<SearchResult> results = ctx.search(ldapSearchBase, searchFilter, searchControls);

        SearchResult searchResult = null;

        while (results.hasMoreElements()) {
            searchResult = (SearchResult) results.nextElement();

            //Create User from searchResult Attributes and add to a List
        }

When this Java code finishes, i have a List with 1k Users, so the problem is obviously that only 1k Users get fetched.

The Question:

How do i tell Java to fetch 1k Users -> write to a List -> get the next 1k until there are no more Users left to fetch.

Thanks in advance!

The answer depends on the LDAP directory that you are using. I assume that it is Active Directory if you were using C#. This post describes how to use the paged results control to avoid hitting the 1000 limit.

And no, the 1000 limit is not universal across all LDAP server implementations. It is a limit that Active Directory is using by default. The alternative to using the paged results control would be to increase the MaxPageSize limit.

The answer to a relative similar question can be found in answer #1 in this thread:

Retrieving user attributes from Active Directory using LDAP - JAVA

BR

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM