Ivan A. Malich
Ivan A. Malich

Reputation: 109

Querying AD with Spring LDAP using paged response (PagedResultsDirContextProcessor) under linux doesn't work

I have such a method in my bean:

/**
*
* @param searchBase - The base DN where the search should start.
* @return List of EmployeeContacts built from persons found in AD under the searchBase
*/
private List<EmployeeContact> getAllPersonsFromBase(String searchBase) {
   final PagedResultsDirContextProcessor processor = new
                                      PagedResultsDirContextProcessor(500);
   final SearchControls searchControls = new SearchControls();
   searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);

   return SingleContextSource.doWithSingleContext(
           contextSource,
           singleContextLdapOperations -> {
               List<EmployeeContact> result = new LinkedList<>();
               do {
                   List<EmployeeContact> oneResult = singleContextLdapOperations.search(
                           searchBase,
                           "(&(objectClass=user)(objectCategory=person))",
                           searchControls,
                           this::mapAttributesToEmployeeContact,
                           processor);
                   result.addAll(oneResult);
               } while(processor.hasMore());
               return result;
               });
}

It works perfectly under my Windows 10 (Oracle JDK 11.0.9). Tested it on a clean VM with Windows 10 and had the same result - works as it should.

But I have problems running it under Ubuntu. Tried JDK from 11.0.8 to 11.0. The result is always the same.

When the search result contains less than 500 (hardcoded in the method) records it works fine. But when the result is paged it fails with:

2021-05-07T18:50:50,380 INFO  [scheduling-1] org.spr.lda.con.AbstractFallbackRequestAndResponseControlDirContextProcessor: No matching response control found - looking for 'class javax.naming.ldap.PagedResultsResponseControl
2021-05-07T18:50:50,381 ERROR [scheduling-1] biz.san.it.int.sw_.ADReader: Exception been caught while querying Active Directory. Exception:
java.lang.ClassCastException: class java.lang.String cannot be cast to class [B (java.lang.String and [B are in module java.base of loader 'bootstrap')

Looks like it cannot load class javax.naming.ldap.PagedResultsResponseControl when it runs under Ubuntu. And then it fails with the strange exception probably because of unpredictable response. When the search result returns less then 500 records it works fine. But when the result is paged it fails.

Upvotes: 1

Views: 1164

Answers (1)

Ivan A. Malich
Ivan A. Malich

Reputation: 109

The problem was in application.yaml encoding. Something with CRLF. The file has been edited in windows notepad and then transferred to Linux VM. When I edited the file with vim changing some lines in ldap config section and then restarted my service the problem has gone.

Upvotes: 1

Related Questions