@Override
    public Collection<User> getUsers(int startIndex, int numResults) {
        final List<String> userlist;
        if (manager.isFindUsersFromGroupsEnabled()) {
            final Set<String> allUsers = GroupManager.getInstance().getGroups()
                .stream()
                .map(Group::getAll)
                .flatMap(Collection::stream)
                .map(JID::getNode)
                .collect(Collectors.toSet());
            userlist = LdapManager.sortAndPaginate(allUsers, startIndex, numResults);
        } else {
            userlist = manager.retrieveList(
                manager.getUsernameField(),
                MessageFormat.format(manager.getSearchFilter(), "*"),
                startIndex,
                numResults,
                manager.getUsernameSuffix(),
                true
            );
        }
        return new UserCollection(userlist.toArray(new String[userlist.size()]));
    }
LDAP implementation of the UserProvider interface. All data in the directory is
treated as read-only so any set operations will result in an exception.

@author Matt Tucker
xmppserver/src/main/java/org/jivesoftware/openfire/ldap/LdapUserProvider.java