UserRoleDaoService { public void setLogicalRoles( LogicalRoleAssignments roleAssignments ) throws SecurityException { if ( canAdminister() ) { for ( LogicalRoleAssignment roleAssignment : roleAssignments.getAssignments() ) { getRoleBindingDao().setRoleBindings( roleAssignment.getRoleName(), roleAssignment.getLogicalRoles() ); } } 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 testSetLogicalRoles() { String roleName = "testRole"; ArrayList<String> roleList = new ArrayList<>(); roleList.add( "org.pentaho.repository.read" ); roleList.add( "org.pentaho.repository.create" ); LogicalRoleAssignment roleAssignment = mock( LogicalRoleAssignment.class ); when( roleAssignment.getRoleName() ).thenReturn( roleName ); when( roleAssignment.getLogicalRoles() ).thenReturn( roleList ); ArrayList<LogicalRoleAssignment> roles = new ArrayList<>(); roles.add( roleAssignment ); LogicalRoleAssignments roleAssignments = mock( LogicalRoleAssignments.class ); when( roleAssignments.getAssignments() ).thenReturn( roles ); setupMockSessionUser( SESSION_USER_NAME, true ); IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = mock( IRoleAuthorizationPolicyRoleBindingDao.class ); PentahoSystem.registerObject( roleBindingDao ); userRoleService.setLogicalRoles( roleAssignments ); verify( roleBindingDao ).setRoleBindings( roleName, roleList ); }
@Test( expected = SecurityException.class ) public void testSetLogicalRolesSecurityException() { LogicalRoleAssignments roleAssignments = mock( LogicalRoleAssignments.class ); setupMockSessionUser( SESSION_USER_NAME, false ); userRoleService.setLogicalRoles( roleAssignments ); }