简体   繁体   English

来自JAVA中LDAP中所有用户

[英]All Users from in LDAP in JAVA

i want to fetch all active Users from an LDAP. 我想从LDAP获取所有活动用户。 The LDAP has way over 1k Users (afaik you can only take 1k Users from Ldap in one request). LDAP有1k个用户(afaik,您只能在一个请求中从Ldap接收1k个用户)。 When using C# i used this: 使用C#时,我使用了以下方法:

//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. 现在,我必须做同样的事情,但是要用Java代码。 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. 当此Java代码完成时,我有一个包含1k个用户的列表,因此问题显然是只有1k个用户被获取。

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. 我如何告诉Java获取1k用户->写入列表->获取下一个1k,直到没有更多用户可获取。

Thanks in advance! 提前致谢!

The answer depends on the LDAP directory that you are using. 答案取决于您使用的LDAP目录。 I assume that it is Active Directory if you were using C#. 如果您使用的是C#,我假设它是Active Directory。 This post describes how to use the paged results control to avoid hitting the 1000 limit. 这篇文章介绍了如何使用分页结果控件来避免达到1000个限制。

And no, the 1000 limit is not universal across all LDAP server implementations. 不,在所有LDAP服务器实现中1000限制不是通用的。 It is a limit that Active Directory is using by default. 默认情况下,Active Directory使用此限制。 The alternative to using the paged results control would be to increase the MaxPageSize limit. 使用分页结果控件的替代方法是增加MaxPageSize限制。

The answer to a relative similar question can be found in answer #1 in this thread: 相对类似问题的答案可以在该线程的答案#1中找到:

Retrieving user attributes from Active Directory using LDAP - JAVA 使用LDAP从Active Directory检索用户属性-JAVA

BR BR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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