DefaultLdapUserRoleListService implements IUserRoleListService, InitializingBean { @Override public List<String> getUsersInRole( final ITenant tenant, final String role ) { if ( tenant != null && !tenant.equals( JcrTenantUtils.getDefaultTenant() ) ) { throw new UnsupportedOperationException( "only allowed to access to default tenant" ); } String updateRole = roleNameUtils.getPrincipleName( role ); List<String> results = usernamesInRoleSearch.search( new Object[] { roleMapper.fromPentahoRole( updateRole ) } ); if ( null != usernameComparator ) { Collections.sort( results, usernameComparator ); } return results; } DefaultLdapUserRoleListService();  DefaultLdapUserRoleListService( final Comparator<String> usernameComparator,
      final Comparator<String> roleComparator );  DefaultLdapUserRoleListService( final Comparator<String> usernameComparator,
      final Comparator<String> roleComparator, final IAuthenticationRoleMapper roleMapper ); @Override void afterPropertiesSet(); @Override List<String> getAllRoles(); @Override List<String> getAllUsers(); @Override List<String> getUsersInRole( final ITenant tenant, final String role ); @Override List<String> getRolesForUser( final ITenant tenant, final String username ); void setAllUsernamesSearch( final LdapSearch allUsernamesSearch ); void setAllAuthoritiesSearch( final LdapSearch allAuthoritiesSearch ); void setUsernamesInRoleSearch( final LdapSearch usernamesInRoleSearch ); void setUserDetailsService( final UserDetailsService userDetailsService ); void setRoleComparator( final Comparator<String> roleComparator ); void setUsernameComparator( final Comparator<String> usernameComparator ); ITenantedPrincipleNameResolver getUserNameUtils(); void setUserNameUtils( ITenantedPrincipleNameResolver userNameUtils ); ITenantedPrincipleNameResolver getRoleNameUtils(); void setRoleNameUtils( ITenantedPrincipleNameResolver roleNameUtils ); @Override List<String> getAllRoles( ITenant tenant ); @Override List<String> getAllUsers( ITenant tenant ); @Override List<String> getSystemRoles(); void setSystemRoles( List<String> systemRoles ); void setExtraRoles( List<String> extraRoles ); List<String> getExtraRoles();  }
@Test( expected = UnsupportedOperationException.class ) public void testGetUsersInRole_nonDefaultTenant() throws Exception { service.getUsersInRole( tenant, "any" ); }
@Test public void testGetUsersInRole() throws Exception { List<String> powerUsers = Arrays.asList( new String[] { "admin", "suzy" } ); service = new DefaultLdapUserRoleListService( usernameComparator, roleComparator, roleMapper ); service.setRoleNameUtils( roleNameUtils ); assertEquals( roleNameUtils, service.getRoleNameUtils() ); service.setUsernamesInRoleSearch( usersInRoleSearch ); when( roleNameUtils.getPrincipleName( anyString() ) ).thenReturn( "rock star" ); when( roleMapper.fromPentahoRole( "rock star" ) ).thenReturn( "power user" ); when( usersInRoleSearch.search( any( filterArgs.getClass() ) ) ).thenReturn( powerUsers ); List<String> foundUsers = service.getUsersInRole( JcrTenantUtils.getDefaultTenant(), "rock star" ); assertNotNull( foundUsers ); assertEquals( 2, foundUsers.size() ); verify( usernameComparator ).compare( anyString(), anyString() ); }