Search in sources :

Example 41 with ITenant

use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.

the class JcrRoleAuthorizationPolicyRoleBindingDao method setRoleBindings.

@Override
public void setRoleBindings(final ITenant tenant, final String runtimeRoleName, final List<String> logicalRoleNames) {
    ITenant tempTenant = tenant;
    if (tenant == null) {
        tempTenant = JcrTenantUtils.getTenant(runtimeRoleName, false);
    }
    if (!TenantUtils.isAccessibleTenant(tempTenant)) {
        throw new NotFoundException("Tenant " + tenant.getId() + " not found");
    }
    Assert.notNull(logicalRoleNames);
    jcrTemplate.execute(new JcrCallback() {

        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            setRoleBindings(session, tenant, runtimeRoleName, logicalRoleNames);
            return null;
        }
    });
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) NotFoundException(org.pentaho.platform.api.engine.security.userroledao.NotFoundException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) JcrCallback(org.springframework.extensions.jcr.JcrCallback) Session(javax.jcr.Session)

Example 42 with ITenant

use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.

the class UserRoleDaoUserRoleListService method getRolesForUser.

@Override
public List<String> getRolesForUser(ITenant tenant, String username) throws UsernameNotFoundException, DataAccessException {
    String userToSearch = username;
    // Extract Tenant from the user name
    ITenant tenantFromUser = JcrTenantUtils.getTenant(username, true);
    if (tenantFromUser == null || tenantFromUser.getId() == null) {
        // No tenant information in the user name so we check the tenant argument
        if (tenant == null || tenant.getId() == null) {
            // No tenant provided so we assume default tenant
            tenant = JcrTenantUtils.getDefaultTenant();
        }
        userToSearch = usernamePrincipalResolver.getPrincipleId(tenant, username);
    }
    UserDetails user = userDetailsService.loadUserByUsername(userToSearch);
    List<String> roles = new ArrayList<String>(user.getAuthorities().size());
    for (GrantedAuthority role : user.getAuthorities()) {
        String principalName = role.getAuthority();
        roles.add(principalName);
    }
    return roles;
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) UserDetails(org.springframework.security.core.userdetails.UserDetails) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList)

Example 43 with ITenant

use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.

the class MetadataRepositoryLifecycleManagerIT method testDoNewTenant.

@Test
public void testDoNewTenant() throws Exception {
    loginAsRepositoryAdmin();
    ITenant systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminAuthorityName, tenantAuthenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminAuthorityName });
    ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminAuthorityName, tenantAuthenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(mainTenant_1, "admin", "password", "", new String[] { adminAuthorityName, tenantAuthenticatedAuthorityName });
    login("admin", mainTenant_1, new String[] { adminAuthorityName, tenantAuthenticatedAuthorityName });
    JcrRepositoryDumpToFile dumpToFile = new JcrRepositoryDumpToFile(testJcrTemplate, jcrTransactionTemplate, repositoryAdminUsername, "c:/build/testrepo_3", Mode.CUSTOM);
    dumpToFile.execute();
    metadataRepositoryLifecycleManager.newTenant(mainTenant_1);
    String metadataPath = ClientRepositoryPaths.getEtcFolderPath() + "/metadata";
    RepositoryFile metadataRepositoryPath = repo.getFile(metadataPath);
    assertTrue(metadataRepositoryPath.getPath() != null);
    // Nothing should change if we run it again
    metadataRepositoryLifecycleManager.newTenant(mainTenant_1);
    metadataPath = ClientRepositoryPaths.getEtcFolderPath() + "/metadata";
    metadataRepositoryPath = repo.getFile(metadataPath);
    assertTrue(metadataRepositoryPath.getPath() != null);
    cleanupUserAndRoles(mainTenant_1);
    cleanupUserAndRoles(systemTenant);
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) JcrRepositoryDumpToFile(org.pentaho.platform.repository2.unified.jcr.JcrRepositoryDumpToFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test)

Example 44 with ITenant

use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.

the class RepositoryImportResourceIT method setUp.

@Before
public void setUp() throws ObjectFactoryException {
    PentahoSystem.init();
    ITenant tenat = mock(ITenant.class);
    resolver = mock(ITenantedPrincipleNameResolver.class);
    doReturn(tenat).when(resolver).getTenant(anyString());
    doReturn(REAL_USER).when(resolver).getPrincipleName(anyString());
    policy = mock(IAuthorizationPolicy.class);
    pentahoObjectFactory = mock(IPentahoObjectFactory.class);
    when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
    when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (invocation.getArguments()[0].equals(IAuthorizationPolicy.class)) {
                return policy;
            }
            if (invocation.getArguments()[0].equals(ITenantedPrincipleNameResolver.class)) {
                return resolver;
            }
            return null;
        }
    });
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
    IPentahoSession session = mock(IPentahoSession.class);
    doReturn("sampleSession").when(session).getName();
    PentahoSessionHolder.setSession(session);
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ITenantedPrincipleNameResolver(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver) Before(org.junit.Before)

Example 45 with ITenant

use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.

the class DefaultUnifiedRepositoryAuthorizationIT method testStopThenStartInheriting.

@Test
public void testStopThenStartInheriting() throws Exception {
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    userRoleDao.createUser(tenantAcme, USERNAME_TIFFANY, PASSWORD, "", null);
    login(USERNAME_TIFFANY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    RepositoryFile tiffanyHomeFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_TIFFANY));
    RepositoryFile testFolder = repo.createFolder(tiffanyHomeFolder.getId(), new RepositoryFile.Builder("test").folder(true).build(), null);
    RepositoryFileAcl acl = repo.getAcl(testFolder.getId());
    RepositoryFileAcl updatedAcl = new RepositoryFileAcl.Builder(acl).entriesInheriting(false).build();
    updatedAcl = repo.updateAcl(updatedAcl);
    assertFalse(updatedAcl.isEntriesInheriting());
    updatedAcl = new RepositoryFileAcl.Builder(updatedAcl).entriesInheriting(true).build();
    updatedAcl = repo.updateAcl(updatedAcl);
    assertTrue(updatedAcl.isEntriesInheriting());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Aggregations

ITenant (org.pentaho.platform.api.mt.ITenant)174 Test (org.junit.Test)120 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)86 Matchers.anyString (org.mockito.Matchers.anyString)47 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)27 ArrayList (java.util.ArrayList)21 Tenant (org.pentaho.platform.core.mt.Tenant)21 ByteArrayInputStream (java.io.ByteArrayInputStream)17 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)17 RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)15 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)14 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)14 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)12 WebResource (com.sun.jersey.api.client.WebResource)11 JerseyTest (com.sun.jersey.test.framework.JerseyTest)11 ITenantedPrincipleNameResolver (org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver)10 SampleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData)10 Serializable (java.io.Serializable)9 Date (java.util.Date)9 HashMap (java.util.HashMap)9