Search in sources :

Example 61 with ITenant

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

the class DefaultUnifiedRepositoryAuthorizationIT method testRoleAuthorizationPolicyTenants.

@Test
public void testRoleAuthorizationPolicyTenants() throws Exception {
    ITenant tenantAcme = null;
    List<String> origLogicalRoles = null;
    try {
        loginAsSysTenantAdmin();
        origLogicalRoles = roleBindingDao.getBoundLogicalRoleNames(Arrays.asList("acme_Authenticated"));
        tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
        userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
        ITenant tenantDuff = tenantManager.createTenant(systemTenant, TENANT_ID_DUFF, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
        userRoleDao.createUser(tenantDuff, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
        login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
        userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
        userRoleDao.createUser(tenantDuff, USERNAME_PAT, PASSWORD, "", null);
        assertEquals(5, authorizationPolicy.getAllowedActions(null).size());
        login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
        assertEquals(3, authorizationPolicy.getAllowedActions(null).size());
        // login with admin (in tenant acme)
        login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
        roleBindingDao.setRoleBindings(tenantAuthenticatedRoleName, Arrays.asList(RepositoryReadAction.NAME, RepositoryCreateAction.NAME, SchedulerAction.NAME, AdministerSecurityAction.NAME));
        assertEquals(5, authorizationPolicy.getAllowedActions(null).size());
        // login with pat (in tenant duff)
        login(USERNAME_PAT, tenantDuff, new String[] { tenantAuthenticatedRoleName });
        assertEquals(3, authorizationPolicy.getAllowedActions(null).size());
        // login with suzy again (in tenant acme); expect additional action for suzy
        login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
        assertEquals(4, authorizationPolicy.getAllowedActions(null).size());
    } finally {
        login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
        // must do it this way in order to reset the cache
        roleBindingDao.setRoleBindings(tenantAuthenticatedRoleName, origLogicalRoles);
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 62 with ITenant

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

the class DefaultUnifiedRepositoryAuthorizationIT method testDeleteSid.

@Test
public void testDeleteSid() throws Exception {
    loginAsSysTenantAdmin();
    ITenant tenantDuff = tenantManager.createTenant(systemTenant, TENANT_ID_DUFF, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantDuff, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, tenantDuff, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    IPentahoUser userGeorge = userRoleDao.createUser(tenantDuff, USERNAME_GEORGE, PASSWORD, "", null);
    userRoleDao.createUser(tenantDuff, USERNAME_PAT, PASSWORD, "", null);
    login(USERNAME_GEORGE, tenantDuff, new String[] { tenantAuthenticatedRoleName });
    RepositoryFile parentFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()));
    RepositoryFile newFile = createSampleFile(parentFolder.getPath(), "hello.xaction", "", false, 2, false);
    RepositoryFileAcl acls = repo.getAcl(newFile.getId());
    RepositoryFileAcl.Builder newAclBuilder = new RepositoryFileAcl.Builder(acls);
    newAclBuilder.entriesInheriting(false).ace(userNameUtils.getPrincipleId(tenantDuff, USERNAME_PAT), RepositoryFileSid.Type.USER, RepositoryFilePermission.ALL);
    repo.updateAcl(newAclBuilder.build());
    login(USERNAME_PAT, tenantDuff, new String[] { tenantAuthenticatedRoleName });
    userRoleDao.deleteUser(userGeorge);
    // TestPrincipalProvider.enableGeorgeAndDuff(false); simulate delete of george who is owner and explicitly in
    // ACE
    RepositoryFile fetchedFile = repo.getFileById(newFile.getId());
    assertEquals(USERNAME_GEORGE, repo.getAcl(fetchedFile.getId()).getOwner().getName());
    assertEquals(RepositoryFileSid.Type.USER, repo.getAcl(fetchedFile.getId()).getOwner().getType());
    RepositoryFileAcl updatedAcl = repo.getAcl(newFile.getId());
    boolean foundGeorge = false;
    for (RepositoryFileAce ace : updatedAcl.getAces()) {
        if (USERNAME_GEORGE.equals(ace.getSid().getName())) {
            foundGeorge = true;
        }
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 63 with ITenant

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

the class DefaultUnifiedRepositoryContentIT method testCreateNodeFile.

@Test
public void testCreateNodeFile() 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_SUZY, PASSWORD, "", null);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    final String expectedName = "helloworld.doesnotmatter";
    final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    final String expectedPath = parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
    final String serverPath = ServerRepositoryPaths.getTenantRootFolderPath() + parentFolderPath + RepositoryFile.SEPARATOR + "helloworld2.sample";
    RepositoryFile sampleFile = createSampleFile(parentFolderPath, "helloworld2.sample", "dfdd", true, 83);
    final Date EXP_DATE = new Date();
    DataNode node = new DataNode("kdjd");
    node.setProperty("ddf", "ljsdfkjsdkf");
    DataNode newChild1 = node.addNode("herfkmdx");
    newChild1.setProperty("sdfs", true);
    newChild1.setProperty("ks3", EXP_DATE);
    newChild1.setProperty("ids32", 7.32D);
    newChild1.setProperty("erere3", 9856684583L);
    newChild1.setProperty("tttss4", "843skdfj33ksaljdfj");
    newChild1.setProperty("urei2", new DataNodeRef(sampleFile.getId()));
    DataNode newChild2 = node.addNode(JcrStringHelper.fileNameEncode("pppq/qqs2"));
    newChild2.setProperty(JcrStringHelper.fileNameEncode("ttt*ss4"), "843skdfj33ksaljdfj");
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(expectedName).build(), data, null);
    assertNotNull(newFile.getId());
    RepositoryFile foundFile = repo.getFile(expectedPath);
    assertNotNull(foundFile);
    assertEquals(expectedName, foundFile.getName());
    DataNode foundNode = repo.getDataForRead(foundFile.getId(), NodeRepositoryFileData.class).getNode();
    assertEquals(node.getName(), foundNode.getName());
    assertNotNull(foundNode.getId());
    assertEquals(node.getProperty("ddf"), foundNode.getProperty("ddf"));
    int actualPropCount = 0;
    for (DataProperty prop : foundNode.getProperties()) {
        actualPropCount++;
    }
    assertEquals(1, actualPropCount);
    assertTrue(foundNode.hasNode("herfkmdx"));
    DataNode foundChild1 = foundNode.getNode("herfkmdx");
    assertNotNull(foundChild1.getId());
    assertEquals(newChild1.getName(), foundChild1.getName());
    assertEquals(newChild1.getProperty("sdfs"), foundChild1.getProperty("sdfs"));
    assertEquals(newChild1.getProperty("ks3"), foundChild1.getProperty("ks3"));
    assertEquals(newChild1.getProperty("ids32"), foundChild1.getProperty("ids32"));
    assertEquals(newChild1.getProperty("erere3"), foundChild1.getProperty("erere3"));
    assertEquals(newChild1.getProperty("tttss4"), foundChild1.getProperty("tttss4"));
    assertEquals(newChild1.getProperty("urei2"), foundChild1.getProperty("urei2"));
    try {
        repo.deleteFile(sampleFile.getId(), true, null);
        fail();
    } catch (UnifiedRepositoryException e) {
    // should fail due to referential integrity (newFile payload has reference to sampleFile)
    }
    actualPropCount = 0;
    for (DataProperty prop : newChild1.getProperties()) {
        actualPropCount++;
    }
    assertEquals(6, actualPropCount);
    assertTrue(foundNode.hasNode(JcrStringHelper.fileNameEncode("pppq/qqs2")));
    DataNode foundChild2 = foundNode.getNode(JcrStringHelper.fileNameEncode("pppq/qqs2"));
    assertNotNull(foundChild2.getId());
    assertEquals(newChild2.getName(), foundChild2.getName());
    assertEquals(newChild2.getProperty(JcrStringHelper.fileNameEncode("ttt:ss4")), foundChild2.getProperty(JcrStringHelper.fileNameEncode("ttt:ss4")));
    actualPropCount = 0;
    for (DataProperty prop : foundChild2.getProperties()) {
        actualPropCount++;
    }
    assertEquals(1, actualPropCount);
    // ordering
    int i = 0;
    for (DataNode currentNode : foundNode.getNodes()) {
        if (i++ == 0) {
            assertEquals(newChild1.getName(), currentNode.getName());
        } else {
            assertEquals(newChild2.getName(), currentNode.getName());
        }
    }
}
Also used : DataNodeRef(org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef) ITenant(org.pentaho.platform.api.mt.ITenant) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) Test(org.junit.Test)

Example 64 with ITenant

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

the class DefaultUnifiedRepositoryContentIT method testGetRoot.

@Test
public void testGetRoot() 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_SUZY, PASSWORD, "", null);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    RepositoryFile rootFolder = repo.getFile("/");
    assertNotNull(rootFolder);
    assertEquals("", rootFolder.getName());
    assertNotNull(rootFolder.getId());
    assertNotNull(repo.getChildren(new RepositoryRequest(String.valueOf(rootFolder.getId()), true, -1, null)));
    RepositoryFileAcl rootFolderAcl = repo.getAcl(rootFolder.getId());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 65 with ITenant

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

the class DefaultUnifiedRepositoryContentIT method testUndeleteFile.

@Test
public void testUndeleteFile() throws Exception {
    Date testBegin = new Date();
    Thread.sleep(1000);
    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_SUZY, PASSWORD, "", null);
    userRoleDao.createUser(tenantAcme, USERNAME_TIFFANY, PASSWORD, "", null);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName());
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    final String fileName = "helloworld.sample";
    RepositoryFile newFile = createSampleFile(parentFolderPath, fileName, "dfdfd", true, 3, true);
    List<RepositoryFile> deletedFiles = repo.getDeletedFiles();
    assertEquals(0, deletedFiles.size());
    repo.deleteFile(newFile.getId(), null);
    deletedFiles = repo.getDeletedFiles();
    assertEquals(1, deletedFiles.size());
    deletedFiles = repo.getDeletedFiles(parentFolder.getPath());
    assertEquals(1, deletedFiles.size());
    assertTrue(testBegin.before(deletedFiles.get(0).getDeletedDate()));
    assertEquals(parentFolder.getPath(), deletedFiles.get(0).getOriginalParentFolderPath());
    assertEquals(newFile.getId(), deletedFiles.get(0).getId());
    deletedFiles = repo.getDeletedFiles(parentFolder.getPath(), "*.sample");
    assertEquals(1, deletedFiles.size());
    assertTrue(testBegin.before(deletedFiles.get(0).getDeletedDate()));
    assertEquals(parentFolder.getPath(), deletedFiles.get(0).getOriginalParentFolderPath());
    deletedFiles = repo.getDeletedFiles(parentFolder.getPath(), "*.doesnotexist");
    assertEquals(0, deletedFiles.size());
    deletedFiles = repo.getDeletedFiles();
    assertEquals(1, deletedFiles.size());
    assertEquals(parentFolder.getPath(), deletedFiles.get(0).getOriginalParentFolderPath());
    assertTrue(testBegin.before(deletedFiles.get(0).getDeletedDate()));
    assertEquals(newFile.getId(), deletedFiles.get(0).getId());
    login(USERNAME_TIFFANY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    // tiffany shouldn't see suzy's deleted file
    assertEquals(0, repo.getDeletedFiles().size());
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    repo.undeleteFile(newFile.getId(), null);
    assertEquals(0, repo.getDeletedFiles(parentFolder.getPath()).size());
    assertEquals(0, repo.getDeletedFiles().size());
    newFile = repo.getFileById(newFile.getId());
    // next two fields only populated when going through the delete-related API calls
    assertNull(newFile.getDeletedDate());
    assertNull(newFile.getOriginalParentFolderPath());
    repo.deleteFile(newFile.getId(), null);
    // permanent delete
    repo.deleteFile(newFile.getId(), true, null);
    try {
        repo.undeleteFile(newFile.getId(), null);
        fail();
    } catch (UnifiedRepositoryException e) {
    // ignore
    }
    // test preservation of original path even if that path no longer exists
    RepositoryFile publicFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()));
    RepositoryFile test1Folder = repo.createFolder(publicFolder.getId(), new RepositoryFile.Builder("test1").folder(true).build(), null);
    newFile = createSampleFile(test1Folder.getPath(), fileName, "dfdfd", true, 3);
    repo.deleteFile(newFile.getId(), null);
    assertNull(repo.getFile("/home/suzy/test1/helloworld.sample"));
    // rename original parent folder
    repo.moveFile(test1Folder.getId(), ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + "test2", null);
    assertNull(repo.getFile(test1Folder.getPath()));
    repo.undeleteFile(newFile.getId(), null);
    assertNotNull(repo.getFile("/home/suzy/test1/helloworld.sample"));
    // repo should create any missing folders
    assertNull(repo.getFile("/home/suzy/test2/helloworld.sample"));
    // on undelete
    assertEquals("/home/suzy/test1/helloworld.sample", repo.getFileById(newFile.getId()).getPath());
    // test versioned parent folder
    RepositoryFile test5Folder = repo.createFolder(publicFolder.getId(), new RepositoryFile.Builder("test5").folder(true).versioned(true).build(), null);
    int versionCountBefore = repo.getVersionSummaries(test5Folder.getId()).size();
    RepositoryFile newFile5 = createSampleFile(test5Folder.getPath(), fileName, "dfdfd", true, 3);
    repo.deleteFile(newFile5.getId(), null);
    assertTrue(repo.getVersionSummaries(test5Folder.getId()).size() > versionCountBefore);
    versionCountBefore = repo.getVersionSummaries(test5Folder.getId()).size();
    repo.undeleteFile(newFile5.getId(), null);
    assertTrue(repo.getVersionSummaries(test5Folder.getId()).size() > versionCountBefore);
    // test permanent delete without undelete
    RepositoryFile newFile6 = createSampleFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()), fileName, "dfdfd", true, 3);
    repo.deleteFile(newFile6.getId(), true, null);
    // test undelete where path to restored file already exists
    RepositoryFile newFile7 = createSampleFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()), fileName, "dfdfd", true, 3);
    repo.deleteFile(newFile7.getId(), null);
    createSampleFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()), fileName, "dfdfd", true, 3);
    try {
        repo.undeleteFile(newFile7.getId(), null);
        fail();
    } catch (UnifiedRepositoryException e) {
        e.printStackTrace();
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) 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