LDAP: fix determining objectclasses takes long

Fixes walk through of possibly all LDAP user entries when determining objectClasses, which results in really bad performance with bigger user bases. Includes also a fix for a potential infinity loop. And adds tests for the method in question.

**Update**
Problem before commit: You go to the LDAP Wizard, fill out the first tab and continue to the next one (User Filter), the wizard tries to determine the objectlcasses i.e. options for the first drop-down select box. If you have an army of users (say ~20-50k) it will take an eternity or two, because every single object is looked at.

Solved by the commit: You go to the LDAP Wizard, fill out the first tab and continue to the next one (User Filter), the wizard tries to determine the objectlcasses i.e. options for the first drop-down select box. If you have an army of users (say ~20-50k) and nevertheless the result will be there quickly, because we just need small sample.

The same methods are used to get objectclasses in the group filter (same effect) and also for the group lists in user (if applicable) and group filter (effectively no change).
**/Update**

Fixes #7530 

Please review @DeepDiver1975 @leo-b (do you mind?) @PVince81 or others.