Получить всех пользователей с помощью LDAP с помощью функции Springboot Page - PullRequest
0 голосов
/ 26 марта 2019

У меня есть метод, который соединяет меня с моими ldap-серверами и извлекает всех пользователей, но я хочу интегрировать это с функцией Page в Springboot, есть ли способ сделать это?

Вот мой код:

    ldapUrl = new LDAPURL(ldapConfig.getUrl());

        LDAPConnectionOptions ldapConnectionOptions = new LDAPConnectionOptions();

        ldapConnectionOptions.setConnectTimeoutMillis(50);

        ldapConnection = new LDAPConnection(ldapConnectionOptions, ldapUrl.getHost(), ldapUrl.getPort(),
                "pedro.almeida" + ldapConfig.getLdapDomain(), "8IwFdrYX49");

        // Perform a search to retrieve all users in the server, but only retrieving
        // ten at a time.

        int numSearches = 0;
        int totalEntriesReturned = 0;

        SearchRequest searchRequest = new SearchRequest(ldapConfig.getBaseDn(), SearchScope.SUB,
                Filter.create("(&(objectCategory=user)(memberOf=ou=Users,))"));
        ASN1OctetString resumeCookie = null;
        while (true) {
            searchRequest.setControls(new SimplePagedResultsControl(10, resumeCookie));
            SearchResult searchResult = ldapConnection.search(searchRequest);
            numSearches++;
            totalEntriesReturned += searchResult.getEntryCount();
            for (SearchResultEntry e : searchResult.getSearchEntries()) {
                System.out.println(e.getDN());
            }

            LDAPTestUtils.assertHasControl(searchResult, SimplePagedResultsControl.PAGED_RESULTS_OID);
            SimplePagedResultsControl responseControl = SimplePagedResultsControl.get(searchResult);
            if (responseControl.moreResultsToReturn()) {
                // The resume cookie can be included in the simple paged results
                // control included in the next search to get the next page of results.
                resumeCookie = responseControl.getCookie();
            } else {
                break;
            }
        }

        System.out.println(totalEntriesReturned);
...