Search in sources :

Example 46 with IPentahoRole

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

the class UserRoleDaoIT method testDeleteRole.

@Test
public void testDeleteRole() 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 });
    String role_delim = ((DefaultTenantedPrincipleNameResolver) tenantedRoleNameUtils).getDelimeter();
    IPentahoRole pentahoRole = userRoleDaoProxy.createRole(mainTenant_1, ROLE_6, ROLE_DESCRIPTION_6, null);
    pentahoRole = userRoleDaoProxy.getRole(null, ROLE_6 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
    assertNotNull(pentahoRole);
    logout();
    login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
    try {
        userRoleDaoProxy.deleteRole(pentahoRole);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    pentahoRole = userRoleDaoProxy.getRole(null, ROLE_6 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
    assertNull(pentahoRole);
    assertEquals(DEFAULT_ROLE_COUNT, userRoleDaoProxy.getRoles(mainTenant_1).size());
    pentahoRole = userRoleDaoProxy.createRole(null, ROLE_6 + role_delim + mainTenant_1.getRootFolderAbsolutePath(), ROLE_DESCRIPTION_6, null);
    pentahoRole = userRoleDaoProxy.getRole(mainTenant_1, ROLE_6);
    assertNotNull(pentahoRole);
    userRoleDaoProxy.deleteRole(pentahoRole);
    assertNull(userRoleDaoProxy.getRole(null, ROLE_6 + role_delim + mainTenant_1.getRootFolderAbsolutePath()));
    try {
        userRoleDaoProxy.deleteRole(pentahoRole);
        fail("Exception not thrown");
    } catch (NotFoundException e) {
    // Expected exception
    }
    try {
        pentahoRole = new PentahoRole(null, ROLE_6, ROLE_DESCRIPTION_6);
        userRoleDaoProxy.deleteRole(pentahoRole);
        fail("Exception not thrown");
    } catch (Exception ex) {
    // Expected exception
    }
    try {
        pentahoRole = new PentahoRole(mainTenant_1, null, ROLE_DESCRIPTION_6);
        userRoleDaoProxy.deleteRole(pentahoRole);
        fail("Exception not thrown");
    } catch (NotFoundException e) {
    // Expected exception
    }
    try {
        pentahoRole = new PentahoRole(mainTenant_1, UNKNOWN_ROLE, ROLE_DESCRIPTION_6);
        userRoleDaoProxy.deleteRole(pentahoRole);
        fail("Exception not thrown");
    } catch (NotFoundException e) {
    // Expected exception
    }
}
Also used : NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) DefaultTenantedPrincipleNameResolver(org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) PentahoRole(org.pentaho.platform.security.userroledao.PentahoRole) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) AccessControlException(javax.jcr.security.AccessControlException) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException) Test(org.junit.Test)

Example 47 with IPentahoRole

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

the class UserRoleDaoIT method createAndTestRole.

public void createAndTestRole(ITenant tenant, String roleName) {
    userRoleDaoProxy.createRole(tenant, roleName, ROLE_DESCRIPTION_1, null);
    IPentahoRole pentahoRole = userRoleDaoProxy.getRole(tenant, roleName);
    assertEquals(pentahoRole.getTenant(), tenant);
    assertEquals(pentahoRole.getName(), roleName);
    assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_1);
}
Also used : IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)

Example 48 with IPentahoRole

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

the class UserRoleDaoIT 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)

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