Search in sources :

Example 11 with IPentahoRole

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.

the class UserRoleDaoResourceTest method testGetRolesForUser.

@Test
public void testGetRolesForUser() throws Exception {
    String user = "admin";
    RoleListWrapper roleListWrapper = new RoleListWrapper(new ArrayList<IPentahoRole>());
    when(userRoleService.getRolesForUser(user)).thenReturn(roleListWrapper);
    assertEquals(roleListWrapper, userRoleResource.getRolesForUser(user));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) Test(org.junit.Test)

Example 12 with IPentahoRole

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.

the class UserRoleDaoResourceTest method testGetRolesForUserError.

@Test
public void testGetRolesForUserError() throws Exception {
    String user = "admin";
    RoleListWrapper roleListWrapper = new RoleListWrapper(new ArrayList<IPentahoRole>());
    when(userRoleService.getRolesForUser(user)).thenReturn(roleListWrapper);
    assertEquals(roleListWrapper, userRoleResource.getRolesForUser(user));
    try {
        when(userRoleService.getRolesForUser(user)).thenThrow(new UncategorizedUserRoleDaoException("testException"));
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) UncategorizedUserRoleDaoException(org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException) Matchers.anyString(org.mockito.Matchers.anyString) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) Test(org.junit.Test)

Example 13 with IPentahoRole

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.

the class UserRoleDaoResource_RolesUpdatedTest method setUp.

@Before
public void setUp() {
    UserRoleDaoService service = mock(UserRoleDaoService.class);
    doReturn(new RoleListWrapper(allRoles)).when(service).getRolesForUser(eq(SESSION_USER_NAME));
    resource = new UserRoleDaoResource(mock(IRoleAuthorizationPolicyRoleBindingDao.class), mock(ITenantManager.class), new ArrayList<String>(), ROLE_NAME_ADMINISTRATOR, service);
    session = new StandaloneSession(SESSION_USER_NAME);
    resource = spy(resource);
    doReturn(session).when(resource).getSession();
    userRoleDao = mock(IUserRoleDao.class);
    doReturn(new ArrayList<IPentahoRole>()).when(userRoleDao).getRoles(any(ITenant.class));
    doReturn(mock(ITenant.class)).when(resource).getTenant(anyString());
    doReturn(userRoleDao).when(resource).getUserRoleDao();
    doReturn(true).when(resource).canAdminister();
}
Also used : UserRoleDaoService(org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService) ITenant(org.pentaho.platform.api.mt.ITenant) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) ArrayList(java.util.ArrayList) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Before(org.junit.Before)

Example 14 with IPentahoRole

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.

the class UserRoleDaoEncodeIT method testGetRoles.

@Test
public void testGetRoles() throws Exception {
    int DEFAULT_ROLE_COUNT = 3;
    loginAsRepositoryAdmin();
    systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminRoleName });
    login(sysAdminUserName, systemTenant, new String[] { adminRoleName, authenticatedRoleName });
    mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(mainTenant_1, "admin", "password", "", new String[] { adminRoleName });
    mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(mainTenant_2, "admin", "password", "", new String[] { adminRoleName });
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    userRoleDaoProxy.createRole(mainTenant_1, ROLE_7, ROLE_DESCRIPTION_7, null);
    userRoleDaoProxy.createRole(mainTenant_1, ROLE_8, ROLE_DESCRIPTION_8, null);
    List<IPentahoRole> roles = userRoleDaoProxy.getRoles(mainTenant_1);
    assertEquals(2 + DEFAULT_ROLE_COUNT, roles.size());
    for (IPentahoRole user : roles) {
        if (user.getName().equals(ROLE_7)) {
            assertEquals(user.getTenant(), mainTenant_1);
            assertEquals(user.getDescription(), ROLE_DESCRIPTION_7);
        } else if (user.getName().equals(ROLE_8)) {
            assertEquals(user.getTenant(), mainTenant_1);
            assertEquals(user.getDescription(), ROLE_DESCRIPTION_8);
        }
    }
    try {
        roles = userRoleDaoProxy.getRoles(UNKNOWN_TENANT);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
}
Also used : IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) Test(org.junit.Test)

Example 15 with IPentahoRole

use of org.pentaho.platform.api.engine.security.userroledao.IPentahoRole in project pentaho-platform by pentaho.

the class UserRoleDaoEncodeIT method testCreateRole.

@Test
public void testCreateRole() throws Exception {
    loginAsRepositoryAdmin();
    systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminRoleName });
    login(sysAdminUserName, systemTenant, new String[] { adminRoleName, authenticatedRoleName });
    mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(mainTenant_1, "admin", "password", "", new String[] { adminRoleName });
    mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(mainTenant_2, "admin", "password", "", new String[] { adminRoleName });
    subTenant1_1 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_1, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(subTenant1_1, "admin", "password", "", new String[] { adminRoleName });
    subTenant1_2 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_2, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(subTenant1_2, "admin", "password", "", new String[] { adminRoleName });
    subTenant2_1 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_1, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(subTenant2_1, "admin", "password", "", new String[] { adminRoleName });
    subTenant2_2 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_2, adminRoleName, authenticatedRoleName, "Anonymous");
    userRoleDaoProxy.createUser(subTenant2_2, "admin", "password", "", new String[] { adminRoleName });
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    IPentahoRole pentahoRole;
    userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
    pentahoRole = userRoleDaoProxy.getRole(mainTenant_1, ROLE_1);
    assertEquals(pentahoRole.getTenant(), mainTenant_1);
    assertEquals(pentahoRole.getName(), ROLE_1);
    assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_1);
    int DEFAULT_ROLE_COUNT = 3;
    List<IPentahoRole> roles = userRoleDaoProxy.getRoles(mainTenant_1);
    assertTrue(roles.size() == 1 + DEFAULT_ROLE_COUNT);
    for (IPentahoRole role : roles) {
        if (role.getName() == ROLE_1) {
            pentahoRole = role;
        }
    }
    assertEquals(pentahoRole.getTenant(), mainTenant_1);
    assertEquals(pentahoRole.getName(), ROLE_1);
    assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_1);
    logout();
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
    login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
    pentahoRole = userRoleDaoProxy.createRole(mainTenant_2, ROLE_1, ROLE_DESCRIPTION_2, null);
    pentahoRole = userRoleDaoProxy.getRole(mainTenant_2, ROLE_1);
    assertEquals(pentahoRole.getTenant(), mainTenant_2);
    assertEquals(pentahoRole.getName(), ROLE_1);
    assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_2);
    roles = userRoleDaoProxy.getRoles(mainTenant_2);
    assertTrue(roles.size() == 1 + DEFAULT_ROLE_COUNT);
    for (IPentahoRole role : roles) {
        if (role.getName() == ROLE_1) {
            pentahoRole = role;
        }
    }
    assertEquals(pentahoRole.getTenant(), mainTenant_2);
    assertEquals(pentahoRole.getName(), ROLE_1);
    assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_2);
    logout();
    login("admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        pentahoRole = userRoleDaoProxy.createRole(mainTenant_2, ROLE_1, ROLE_DESCRIPTION_1, null);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    userRoleDaoProxy.createRole(null, ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath(), ROLE_DESCRIPTION_3, null);
    pentahoRole = userRoleDaoProxy.getRole(null, ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath());
    assertEquals(pentahoRole.getTenant(), subTenant2_1);
    assertEquals(pentahoRole.getName(), ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath());
    assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_3);
    roles = userRoleDaoProxy.getRoles(subTenant2_1);
    assertTrue(roles.size() == 1 + DEFAULT_ROLE_COUNT);
    for (IPentahoRole role : roles) {
        if (role.getName() == ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath()) {
            pentahoRole = role;
        }
    }
    assertEquals(pentahoRole.getTenant(), subTenant2_1);
    assertEquals(pentahoRole.getName(), ROLE_3 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant2_1.getRootFolderAbsolutePath());
    assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_3);
    logout();
    login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        pentahoRole = userRoleDaoProxy.createRole(subTenant2_1, ROLE_3, ROLE_DESCRIPTION_3, null);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
    login("admin", subTenant1_1, new String[] { adminRoleName, authenticatedRoleName });
    pentahoRole = userRoleDaoProxy.createRole(null, ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath(), ROLE_DESCRIPTION_4, null);
    pentahoRole = userRoleDaoProxy.getRole(null, ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath());
    assertEquals(pentahoRole.getTenant(), subTenant1_1);
    assertEquals(pentahoRole.getName(), ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath());
    assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_4);
    roles = userRoleDaoProxy.getRoles(subTenant1_1);
    assertTrue(roles.size() == 1 + DEFAULT_ROLE_COUNT);
    for (IPentahoRole role : roles) {
        if (role.getName() == ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath()) {
            pentahoRole = role;
        }
    }
    assertEquals(pentahoRole.getTenant(), subTenant1_1);
    assertEquals(pentahoRole.getName(), ROLE_4 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + subTenant1_1.getRootFolderAbsolutePath());
    assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_4);
    logout();
    login("admin", subTenant2_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        pentahoRole = userRoleDaoProxy.createRole(subTenant1_1, ROLE_3, ROLE_DESCRIPTION_3, null);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    try {
        userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null);
        fail("Exception not thrown");
    } catch (AlreadyExistsException e) {
    // Expected exception
    }
    logout();
}
Also used : AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) Test(org.junit.Test)

Aggregations

IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)48 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)16 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)13 ITenant (org.pentaho.platform.api.mt.ITenant)12 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)10 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)8 HashSet (java.util.HashSet)7 Matchers.anyString (org.mockito.Matchers.anyString)6 NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)6 DefaultTenantedPrincipleNameResolver (org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver)6 IOException (java.io.IOException)5 RepositoryException (javax.jcr.RepositoryException)5 AccessControlException (javax.jcr.security.AccessControlException)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 PentahoRole (org.pentaho.platform.security.userroledao.PentahoRole)4 BeansException (org.springframework.beans.BeansException)4 StringTokenizer (java.util.StringTokenizer)2 Group (org.apache.jackrabbit.api.security.user.Group)2 UncategorizedUserRoleDaoException (org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException)2