Search in sources :

Example 1 with DefaultTenantedPrincipleNameResolver

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

the class DefaultTenantedPrincipleNameResolverTest method testIsValid.

@Test
public void testIsValid() {
    DefaultTenantedPrincipleNameResolver resolver = new DefaultTenantedPrincipleNameResolver();
    resolver.setDelimeter(DefaultTenantedPrincipleNameResolver.ALTERNATE_DELIMETER);
    Assert.assertEquals(resolver.isValid("pentaho_user"), false);
}
Also used : DefaultTenantedPrincipleNameResolver(org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver) Test(org.junit.Test)

Example 2 with DefaultTenantedPrincipleNameResolver

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

the class UserRoleDaoIT method testUpdateRole.

@Test
public void testUpdateRole() 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 });
    login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName });
    IPentahoRole pentahoRole = userRoleDaoProxy.createRole(mainTenant_1, ROLE_5, ROLE_DESCRIPTION_5, null);
    pentahoRole = userRoleDaoProxy.getRole(mainTenant_1, ROLE_5);
    assertEquals(pentahoRole.getDescription(), ROLE_DESCRIPTION_5);
    String changedDescription1 = ROLE_DESCRIPTION_5 + "change1";
    userRoleDaoProxy.setRoleDescription(mainTenant_1, ROLE_5, changedDescription1);
    String role_delim = ((DefaultTenantedPrincipleNameResolver) tenantedRoleNameUtils).getDelimeter();
    pentahoRole = userRoleDaoProxy.getRole(null, ROLE_5 + role_delim + mainTenant_1.getRootFolderAbsolutePath());
    assertNotNull(pentahoRole);
    assertEquals(changedDescription1, pentahoRole.getDescription());
    String changedDescription2 = ROLE_DESCRIPTION_5 + "change2";
    userRoleDaoProxy.setRoleDescription(null, ROLE_5 + role_delim + mainTenant_1.getRootFolderAbsolutePath(), changedDescription2);
    pentahoRole = userRoleDaoProxy.getRole(mainTenant_1, ROLE_5);
    assertEquals(changedDescription2, pentahoRole.getDescription());
    userRoleDaoProxy.setRoleDescription(null, ROLE_5 + role_delim + mainTenant_1.getRootFolderAbsolutePath(), null);
    pentahoRole = userRoleDaoProxy.getRole(mainTenant_1, ROLE_5);
    assertNull(pentahoRole.getDescription());
    try {
        userRoleDaoProxy.setRoleDescription(null, null, changedDescription2);
        fail("Exception not thrown");
    } catch (Exception ex) {
        // Expected exception
        assertNotNull(ex);
    }
    try {
        userRoleDaoProxy.setRoleDescription(mainTenant_1, UNKNOWN_ROLE, changedDescription2);
        fail("Exception not thrown");
    } catch (NotFoundException ex) {
        // Expected exception
        assertNotNull(ex);
    }
    logout();
    login("admin", mainTenant_2, new String[] { adminRoleName, authenticatedRoleName });
    try {
        changedDescription1 = ROLE_DESCRIPTION_5 + "change1";
        userRoleDaoProxy.setRoleDescription(mainTenant_1, ROLE_5, changedDescription1);
        fail("Exception not thrown");
    } catch (Throwable th) {
        assertNotNull(th);
    }
    logout();
}
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) 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 3 with DefaultTenantedPrincipleNameResolver

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

the class ExportManifestEntity method createEntityAcl.

private void createEntityAcl(RepositoryFileAcl repositoryFileAcl) {
    DefaultTenantedPrincipleNameResolver nameResolver = new DefaultTenantedPrincipleNameResolver();
    if (repositoryFileAcl == null) {
        return;
    }
    entityAcl = new EntityAcl();
    entityAcl.setEntriesInheriting(repositoryFileAcl.isEntriesInheriting());
    entityAcl.setOwner(nameResolver.getPrincipleName(repositoryFileAcl.getOwner().getName()));
    entityAcl.setOwnerType(repositoryFileAcl.getOwner().getType().name());
    List<EntityAcl.Aces> aces = entityAcl.getAces();
    aces.clear();
    for (RepositoryFileAce repositoryFileAce : repositoryFileAcl.getAces()) {
        EntityAcl.Aces ace = new EntityAcl.Aces();
        ace.setRecipient(nameResolver.getPrincipleName(repositoryFileAce.getSid().getName()));
        ace.setRecipientType(repositoryFileAce.getSid().getType().name());
        List<String> permissions = ace.getPermissions();
        for (RepositoryFilePermission permission : repositoryFileAce.getPermissions()) {
            permissions.add(permission.toString());
        }
        aces.add(ace);
    }
}
Also used : RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) DefaultTenantedPrincipleNameResolver(org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver) EntityAcl(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.EntityAcl)

Example 4 with DefaultTenantedPrincipleNameResolver

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

the class DefaultUnifiedRepositoryBase method initialize.

public void initialize(boolean multiByteEncoding) throws Exception {
    loginAsRepositoryAdmin();
    SimpleJcrTestUtils.deleteItem(testJcrTemplate, ServerRepositoryPaths.getPentahoRootFolderPath());
    mp = new MicroPlatform(getSolutionPath());
    // used by DefaultPentahoJackrabbitAccessControlHelper
    mp.defineInstance("tenantedUserNameUtils", userNameUtils);
    mp.defineInstance("tenantedRoleNameUtils", roleNameUtils);
    mp.defineInstance("ILockHelper", new DefaultLockHelper(userNameUtils));
    mp.defineInstance(IAuthorizationPolicy.class, authorizationPolicy);
    mp.defineInstance(ITenantManager.class, tenantManager);
    mp.defineInstance("roleAuthorizationPolicyRoleBindingDaoTarget", roleBindingDaoTarget);
    mp.defineInstance("repositoryAdminUsername", repositoryAdminUsername);
    mp.defineInstance("RepositoryFileProxyFactory", new RepositoryFileProxyFactory(this.jcrTemplate, this.repositoryFileDao));
    mp.defineInstance("ITenantedPrincipleNameResolver", new DefaultTenantedPrincipleNameResolver());
    mp.defineInstance("useMultiByteEncoding", multiByteEncoding);
    mp.defineInstance(IUnifiedRepository.class, repo);
    mp.defineInstance(IRepositoryFileAclDao.class, repositoryFileAclDao);
    IUserRoleListService userRoleListService = mock(IUserRoleListService.class);
    when(userRoleListService.getRolesForUser(any(ITenant.class), anyString())).thenReturn(Arrays.asList(tenantAdminRoleName, AUTHENTICATED_ROLE_NAME));
    mp.defineInstance(IUserRoleListService.class, userRoleListService);
    mp.defineInstance("singleTenantAdminUserName", singleTenantAdminUserName);
    mp.defineInstance("singleTenantAdminAuthorityName", tenantAdminRoleName);
    // Start the micro-platform
    mp.start();
    loginAsRepositoryAdmin();
    setAclManagement();
    systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(systemTenant, sysAdminUserName, PASSWORD, "", new String[] { tenantAdminRoleName });
    logout();
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) DefaultLockHelper(org.pentaho.platform.repository2.unified.jcr.DefaultLockHelper) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) DefaultTenantedPrincipleNameResolver(org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) RepositoryFileProxyFactory(org.pentaho.platform.repository2.unified.jcr.RepositoryFileProxyFactory)

Example 5 with DefaultTenantedPrincipleNameResolver

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

Aggregations

DefaultTenantedPrincipleNameResolver (org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver)10 Test (org.junit.Test)7 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)6 IOException (java.io.IOException)4 AccessControlException (javax.jcr.security.AccessControlException)4 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)4 NotFoundException (org.pentaho.platform.api.engine.security.userroledao.NotFoundException)4 BeansException (org.springframework.beans.BeansException)4 ArrayList (java.util.ArrayList)2 RepositoryException (javax.jcr.RepositoryException)2 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)2 PentahoRole (org.pentaho.platform.security.userroledao.PentahoRole)2 IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)1 IAuthenticationRoleMapper (org.pentaho.platform.api.engine.security.IAuthenticationRoleMapper)1 ITenant (org.pentaho.platform.api.mt.ITenant)1 RepositoryFileAce (org.pentaho.platform.api.repository2.unified.RepositoryFileAce)1 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)1 DefaultLdapRoleMapper (org.pentaho.platform.engine.security.DefaultLdapRoleMapper)1 EntityAcl (org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.EntityAcl)1 DefaultLdapUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService)1