我有一种方法可以将我连接到ldap服务器并检索所有用户,但是我想将其与Springboot的Page函数集成,有什么方法可以做到这一点?
这是我的代码:
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);