Source:
<code>public Promise<Users> searchUsers(Collection<String> usernames, int offset, int limit) { final ImmutableList.Builder<User> resultBuilder = ImmutableList.builder(); final String baseDn = conf.getBaseDn(); final String uidProp = conf.getUserIdProperty(); InitialLdapContext context = null; NamingEnumeration<SearchResult> searchResultEnumeration = null; try { context = createLdapContext(); Collection<LdapRole> ldapRoles = getAllLdapRoles(context, baseDn); <START> searchResultEnumeration = context.search(baseDn, ALL_USER_QUERY, createSearchControls(limit, ATTRIBUTE_DN, uidProp)); <END> for (final SearchResult searchResult : ImmutableList.copyOf(Iterators.forEnumeration(searchResultEnumeration))) { final Attributes attributes = searchResult.getAttributes(); if (hasAttribute(attributes, uidProp)) { final String userName = (String) attributes.get(uidProp).get(); final List<Role> userRoles = ldapRoles.stream() .filter(role -> role.getUniqueMembers().contains(searchResult.getNameInNamespace())) .map(role -> new Role(role.getName(), role.getPermissions())) .collect(Collectors.toList()); resultBuilder.add(new User(userName, userRoles)); } } ImmutableList<User> users = resultBuilder.build(); return Promise.immediate(new Users(users, offset, limit, users.size())); } catch (final NamingException e) { throw new SnowowlRuntimeException(e); } finally { closeNamingEnumeration(searchResultEnumeration); closeLdapContext(context); } }</code><technical_language>LDAP queries support operator, resulting query is a bit more complex static; if worth changing it: <LINK_0></technical_language>

Target:
public Promise<Users> searchUsers(Collection<String> usernames, int offset, int limit) { final ImmutableList.Builder<User> resultBuilder = ImmutableList.builder(); final String baseDn = conf.getBaseDn(); final String uidProp = conf.getUserIdProperty(); InitialLdapContext context = null; NamingEnumeration<SearchResult> searchResultEnumeration = null; try { context = createLdapContext(); Collection<LdapRole> ldapRoles = getAllLdapRoles(context, baseDn); searchResultEnumeration = context.search(baseDn, ALL_USER_QUERY, createSearchControls(ATTRIBUTE_DN, uidProp)); for (final SearchResult searchResult : ImmutableList.copyOf(Iterators.forEnumeration(searchResultEnumeration))) { final Attributes attributes = searchResult.getAttributes(); if (hasAttribute(attributes, uidProp)) { final String userName = (String) attributes.get(uidProp).get(); final List<Role> userRoles = ldapRoles.stream() .filter(role -> role.getUniqueMembers().contains(searchResult.getNameInNamespace())) .map(role -> new Role(role.getName(), role.getPermissions())) .collect(Collectors.toList()); resultBuilder.add(new User(userName, userRoles)); } } final List<User> users = resultBuilder.build().stream() .sorted((u1, u2) -> u1.getUsername().compareTo(u2.getUsername())) .filter(user -> usernames.isEmpty() || usernames.contains(user.getUsername())) .skip(offset) .limit(limit) .collect(Collectors.toList()); return Promise.immediate(new Users(users, offset, limit, users.size())); } catch (final NamingException e) { throw new SnowowlRuntimeException(e); } finally { closeNamingEnumeration(searchResultEnumeration); closeLdapContext(context); } }