@Test @SuppressWarnings("unchecked") public void testFindUsers() { List<User> users = IteratorUtils.toList(directory.findUsers("%mple%", 0, 0)); Assert.assertEquals(2, users.size()); Assert.assertTrue(userName.equals(users.get(0).getUsername()) || userName.equals(users.get(1).getUsername())); Assert.assertTrue("userSample".equals(users.get(0).getUsername()) || "userSample".equals(users.get(1).getUsername())); users = IteratorUtils.toList(directory.findUsers("%mple%", 1, 1)); Assert.assertEquals(1, users.size()); }
@Override public Iterator<User> findUsers(String query, int offset, int limit) { if (query == null) throw new IllegalArgumentException("Query must be set"); Organization org = securityService.getOrganization(); if (org == null) throw new IllegalStateException("No organization is set"); final List<User> users = new ArrayList<>(); for (final UserProvider userProvider : userProviders) { String providerOrgId = userProvider.getOrganization(); if (ALL_ORGANIZATIONS.equals(providerOrgId) || org.getId().equals(providerOrgId)) { userProvider.findUsers(query, 0, 0).forEachRemaining(users::add); } } Stream<User> stream = users.stream().sorted(Comparator.comparing(User::getUsername)).skip(offset); if (limit > 0) { return stream.limit(limit).iterator(); } return stream.iterator(); }
UserAndRoleDirectoryServiceImpl implements UserDirectoryService, UserDetailsService, RoleDirectoryService { @Override public Iterator<User> findUsers(String query, int offset, int limit) { if (query == null) throw new IllegalArgumentException("Query must be set"); Organization org = securityService.getOrganization(); if (org == null) throw new IllegalStateException("No organization is set"); final List<User> users = new ArrayList<>(); for (final UserProvider userProvider : userProviders) { String providerOrgId = userProvider.getOrganization(); if (ALL_ORGANIZATIONS.equals(providerOrgId) || org.getId().equals(providerOrgId)) { userProvider.findUsers(query, 0, 0).forEachRemaining(users::add); } } Stream<User> stream = users.stream().sorted(Comparator.comparing(User::getUsername)).skip(offset); if (limit > 0) { return stream.limit(limit).iterator(); } return stream.iterator(); } }
UserAndRoleDirectoryServiceImpl implements UserDirectoryService, UserDetailsService, RoleDirectoryService { @Override public Iterator<User> findUsers(String query, int offset, int limit) { if (query == null) throw new IllegalArgumentException("Query must be set"); Organization org = securityService.getOrganization(); if (org == null) throw new IllegalStateException("No organization is set"); final List<User> users = new ArrayList<>(); for (final UserProvider userProvider : userProviders) { String providerOrgId = userProvider.getOrganization(); if (ALL_ORGANIZATIONS.equals(providerOrgId) || org.getId().equals(providerOrgId)) { userProvider.findUsers(query, 0, 0).forEachRemaining(users::add); } } Stream<User> stream = users.stream().sorted(Comparator.comparing(User::getUsername)).skip(offset); if (limit > 0) { return stream.limit(limit).iterator(); } return stream.iterator(); }  }
UserAndRoleDirectoryServiceImpl implements UserDirectoryService, UserDetailsService, RoleDirectoryService { @Override public Iterator<User> findUsers(String query, int offset, int limit) { if (query == null) throw new IllegalArgumentException("Query must be set"); Organization org = securityService.getOrganization(); if (org == null) throw new IllegalStateException("No organization is set"); final List<User> users = new ArrayList<>(); for (final UserProvider userProvider : userProviders) { String providerOrgId = userProvider.getOrganization(); if (ALL_ORGANIZATIONS.equals(providerOrgId) || org.getId().equals(providerOrgId)) { userProvider.findUsers(query, 0, 0).forEachRemaining(users::add); } } Stream<User> stream = users.stream().sorted(Comparator.comparing(User::getUsername)).skip(offset); if (limit > 0) { return stream.limit(limit).iterator(); } return stream.iterator(); }  @Override Iterator<User> getUsers(); @Override User loadUser(String userName); @Override Iterator<User> loadUsers(Collection<String> userNames); @Override UserDetails loadUserByUsername(String userName); @Reference(name = "securityService") void setSecurityService(SecurityService securityService); @Override Iterator<User> findUsers(String query, int offset, int limit); @Override List<Role> findRoles(String query, Role.Target target, int offset, int limit); @Override long countUsers(); @Override void invalidate(String userName); }
UserAndRoleDirectoryServiceImpl implements UserDirectoryService, UserDetailsService, RoleDirectoryService { @Override public Iterator<User> findUsers(String query, int offset, int limit) { if (query == null) throw new IllegalArgumentException("Query must be set"); Organization org = securityService.getOrganization(); if (org == null) throw new IllegalStateException("No organization is set"); final List<User> users = new ArrayList<>(); for (final UserProvider userProvider : userProviders) { String providerOrgId = userProvider.getOrganization(); if (ALL_ORGANIZATIONS.equals(providerOrgId) || org.getId().equals(providerOrgId)) { userProvider.findUsers(query, 0, 0).forEachRemaining(users::add); } } Stream<User> stream = users.stream().sorted(Comparator.comparing(User::getUsername)).skip(offset); if (limit > 0) { return stream.limit(limit).iterator(); } return stream.iterator(); }  @Override Iterator<User> getUsers(); @Override User loadUser(String userName); @Override Iterator<User> loadUsers(Collection<String> userNames); @Override UserDetails loadUserByUsername(String userName); @Reference(name = "securityService") void setSecurityService(SecurityService securityService); @Override Iterator<User> findUsers(String query, int offset, int limit); @Override List<Role> findRoles(String query, Role.Target target, int offset, int limit); @Override long countUsers(); @Override void invalidate(String userName); static final String USER_CACHE_SIZE_KEY; static final String USER_CACHE_EXPIRY_KEY; }