UserRoleDaoService { public UserListWrapper getRoleMembers( String roleName ) throws UncategorizedUserRoleDaoException, SecurityException { if ( canAdminister() ) { return new UserListWrapper( getRoleDao().getRoleMembers( TenantUtils.getCurrentTenant(), roleName ) ); } else { throw new SecurityException(); } }  UserListWrapper getUsers(); RoleListWrapper getRolesForUser( String user ); void assignRolesToUser( String userName, String roleNames ); void removeRolesFromUser( String userName, String roleNames ); void createRole( String roleName ); RoleListWrapper getRoles(); UserListWrapper getRoleMembers( String roleName ); void createUser( User user ); void changeUserPassword( final String userName, final String newPass, String oldPass ); void deleteUsers( String userNames ); void deleteRoles( String roleNames ); SystemRolesMap getRoleBindingStruct( String locale ); void setLogicalRoles( LogicalRoleAssignments roleAssignments ); void updatePassword( User user, String administratorPassword ); void updatePassword( User user ); static final String PUC_USER_PASSWORD_LENGTH; static final String PUC_USER_PASSWORD_REQUIRE_SPECIAL_CHARACTER; }
@Test public void testGetRoleMembers() { setupMockSessionUser( SESSION_USER_NAME, true ); List<IPentahoUser> userList = new ArrayList<>(); IUserRoleDao roleDao = mock( IUserRoleDao.class ); when( roleDao.getRoleMembers( any( ITenant.class ), anyString() ) ).thenReturn( userList ); PentahoSystem.registerObject( roleDao ); IPentahoUser user = mock( IPentahoUser.class ); when( user.getUsername() ).thenReturn( "admin" ); userList.add( user ); UserListWrapper wrapUserList = new UserListWrapper( userList ); IPentahoSession session = mock( IPentahoSession.class ); String tenantPath = "testPath"; when( session.getAttribute( IPentahoSession.TENANT_ID_KEY ) ).thenReturn( tenantPath ); PentahoSessionHolder.setSession( session ); assertEquals( wrapUserList.getUsers(), userRoleService.getRoleMembers( "Report Author" ).getUsers() ); }
@Test( expected = SecurityException.class ) public void testGetRoleMembersSecurityException() { setupMockSessionUser( SESSION_USER_NAME, false ); List<IPentahoUser> userList = new ArrayList<>(); IUserRoleDao roleDao = mock( IUserRoleDao.class ); when( roleDao.getRoleMembers( any( ITenant.class ), anyString() ) ).thenReturn( userList ); PentahoSystem.registerObject( roleDao ); IPentahoUser user = mock( IPentahoUser.class ); when( user.getUsername() ).thenReturn( "admin" ); userList.add( user ); UserListWrapper wrapUserList = new UserListWrapper( userList ); IPentahoSession session = mock( IPentahoSession.class ); String tenantPath = "testPath"; when( session.getAttribute( IPentahoSession.TENANT_ID_KEY ) ).thenReturn( tenantPath ); PentahoSessionHolder.setSession( session ); userRoleService.getRoleMembers( "Report Author" ); }