Search in sources :

Example 1 with RoleListWrapper

use of org.pentaho.platform.web.http.api.resources.RoleListWrapper in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method testGetRoles.

@Test
public void testGetRoles() throws Exception {
    List<IPentahoRole> roleList = new ArrayList<>();
    IUserRoleDao roleDao = mock(IUserRoleDao.class);
    when(roleDao.getRoles()).thenReturn(roleList);
    PentahoSystem.registerObject(roleDao);
    IPentahoRole role = mock(IPentahoRole.class);
    when(role.getName()).thenReturn("testRole");
    roleList.add(role);
    RoleListWrapper wrapRoleList = new RoleListWrapper(roleList);
    assertEquals(wrapRoleList.getRoles(), userRoleService.getRoles().getRoles());
}
Also used : RoleListWrapper(org.pentaho.platform.web.http.api.resources.RoleListWrapper) ArrayList(java.util.ArrayList) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Test(org.junit.Test)

Example 2 with RoleListWrapper

use of org.pentaho.platform.web.http.api.resources.RoleListWrapper in project pentaho-platform by pentaho.

the class UserRoleListServiceTest method testDoGetRoles.

@Test
public void testDoGetRoles() {
    List<String> roles = new ArrayList<String>();
    roles.add("ROLE1");
    roles.add("ROLE2");
    IUserRoleListService userRoleListService1 = mock(IUserRoleListService.class);
    doReturn(userRoleListService1).when(userRoleListService).getUserRoleListService();
    doReturn(roles).when(userRoleListService1).getAllRoles();
    RoleListWrapper roleListWrapper = userRoleListService.getRoles();
    verify(userRoleListService).getUserRoleListService();
    verify(userRoleListService1).getAllRoles();
    assertEquals(roles, roleListWrapper.getRoles());
}
Also used : RoleListWrapper(org.pentaho.platform.web.http.api.resources.RoleListWrapper) ArrayList(java.util.ArrayList) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Test(org.junit.Test)

Example 3 with RoleListWrapper

use of org.pentaho.platform.web.http.api.resources.RoleListWrapper in project pentaho-platform by pentaho.

the class UserRoleListServiceTest method testGetPermissionRoles.

@Test
public void testGetPermissionRoles() {
    List<String> roles = new ArrayList<String>();
    roles.add("ROLE1");
    roles.add("ROLE2");
    roles.add("ADMIN_ROLE");
    IUserRoleListService userRoleListService1 = mock(IUserRoleListService.class);
    doReturn(userRoleListService1).when(userRoleListService).getUserRoleListService();
    doReturn(roles).when(userRoleListService1).getAllRoles();
    ArrayList<String> extraRoles = new ArrayList<String>();
    extraRoles.add("EXTRA_ROLE1");
    extraRoles.add("EXTRA_ROLE2");
    userRoleListService.setExtraRoles(extraRoles);
    RoleListWrapper roleWrapper = userRoleListService.getPermissionRoles("ADMIN_ROLE");
    assertTrue(!roleWrapper.getRoles().contains("ADMIN_ROLE"));
    assertTrue(roleWrapper.getRoles().size() == 4);
}
Also used : RoleListWrapper(org.pentaho.platform.web.http.api.resources.RoleListWrapper) ArrayList(java.util.ArrayList) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Test(org.junit.Test)

Example 4 with RoleListWrapper

use of org.pentaho.platform.web.http.api.resources.RoleListWrapper in project pentaho-platform by pentaho.

the class UserRoleListService method getPermissionRoles.

public RoleListWrapper getPermissionRoles(String adminRole) {
    IUserRoleListService userRoleListService = getUserRoleListService();
    List<String> allRoles = userRoleListService.getAllRoles();
    // We will not allow user to update permission for Administrator
    if (allRoles.contains(adminRole)) {
        allRoles.remove(adminRole);
    }
    // Add extra roles to the list of roles
    if (extraRoles != null) {
        for (String extraRole : extraRoles) {
            if (!allRoles.contains(extraRole)) {
                allRoles.add(extraRole);
            }
        }
    }
    if (null != roleComparator) {
        Collections.sort(allRoles, roleComparator);
    }
    return new RoleListWrapper(allRoles);
}
Also used : RoleListWrapper(org.pentaho.platform.web.http.api.resources.RoleListWrapper) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService)

Example 5 with RoleListWrapper

use of org.pentaho.platform.web.http.api.resources.RoleListWrapper in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method testGetRolesForUser.

@Test
public void testGetRolesForUser() throws Exception {
    List<IPentahoRole> roleList = new ArrayList<>();
    IUserRoleDao roleDao = mock(IUserRoleDao.class);
    when(roleDao.getUserRoles(any(ITenant.class), anyString())).thenReturn(roleList);
    PentahoSystem.registerObject(roleDao);
    RoleListWrapper wrapRoleList = new RoleListWrapper(roleList);
    IPentahoSession session = mock(IPentahoSession.class);
    String tenantPath = "testPath";
    when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn(tenantPath);
    PentahoSessionHolder.setSession(session);
    setupMockSessionUser(SESSION_USER_NAME, true);
    assertEquals(wrapRoleList.getRoles(), userRoleService.getRolesForUser("admin").getRoles());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) RoleListWrapper(org.pentaho.platform.web.http.api.resources.RoleListWrapper) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Test(org.junit.Test)

Aggregations

RoleListWrapper (org.pentaho.platform.web.http.api.resources.RoleListWrapper)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)4 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)2 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)2 Matchers.anyString (org.mockito.Matchers.anyString)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 ITenant (org.pentaho.platform.api.mt.ITenant)1