Search in sources :

Example 1 with PentahoRole

use of org.pentaho.platform.security.userroledao.PentahoRole in project pentaho-platform by pentaho.

the class AbstractJcrBackedUserRoleDao method convertToPentahoRole.

private IPentahoRole convertToPentahoRole(Group jackrabbitGroup) throws RepositoryException {
    IPentahoRole role = null;
    Value[] propertyValues = null;
    String description = null;
    try {
        // $NON-NLS-1$
        propertyValues = jackrabbitGroup.getProperty("description");
        description = propertyValues.length > 0 ? propertyValues[0].getString() : null;
    } catch (Exception ex) {
    // CHECKSTYLES IGNORE
    }
    role = new PentahoRole(tenantedRoleNameUtils.getTenant(jackrabbitGroup.getID()), tenantedRoleNameUtils.getPrincipleName(jackrabbitGroup.getID()), description);
    return role;
}
Also used : Value(javax.jcr.Value) 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) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) RepositoryException(javax.jcr.RepositoryException) NamespaceException(javax.jcr.NamespaceException) AuthorizableExistsException(org.apache.jackrabbit.api.security.user.AuthorizableExistsException)

Example 2 with PentahoRole

use of org.pentaho.platform.security.userroledao.PentahoRole in project pentaho-platform by pentaho.

the class ProxyPentahoUserRoleHelper method syncRoles.

/**
 * Synchronizes <code>role</code> with fields from <code>proxyRole</code>. The users set of given
 * <code>role</code> is unmodified.
 */
public static IPentahoRole syncRoles(IPentahoRole role, ProxyPentahoRole proxyRole) {
    IPentahoRole syncedRole = role;
    if (syncedRole == null) {
        syncedRole = new PentahoRole(proxyRole.getName());
    }
    syncedRole.setDescription(proxyRole.getDescription());
    return syncedRole;
}
Also used : PentahoRole(org.pentaho.platform.security.userroledao.PentahoRole) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)

Example 3 with PentahoRole

use of org.pentaho.platform.security.userroledao.PentahoRole in project pentaho-platform by pentaho.

the class UserRoleDaoEncodeIT 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) RepositoryException(javax.jcr.RepositoryException) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with PentahoRole

use of org.pentaho.platform.security.userroledao.PentahoRole 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)

Aggregations

IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)4 PentahoRole (org.pentaho.platform.security.userroledao.PentahoRole)4 NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)3 IOException (java.io.IOException)2 RepositoryException (javax.jcr.RepositoryException)2 AccessControlException (javax.jcr.security.AccessControlException)2 Test (org.junit.Test)2 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)2 DefaultTenantedPrincipleNameResolver (org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver)2 BeansException (org.springframework.beans.BeansException)2 NamespaceException (javax.jcr.NamespaceException)1 Value (javax.jcr.Value)1 AuthorizableExistsException (org.apache.jackrabbit.api.security.user.AuthorizableExistsException)1