Search in sources :

Example 26 with ITenant

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

the class FileResourceIT method testBrowserDownload.

// This is testing the Rest end points, we should instead be testing the underlying functionality in unit tests
@Test
public void testBrowserDownload() {
    final String text = "abcdefg";
    // mock converters map
    StreamConverter streamConverter = new StreamConverter(repo);
    Map<String, Converter> converterMap = new HashMap<String, Converter>();
    converterMap.put("txt", streamConverter);
    // stub DefaultExportProcessor
    DefaultExportHandler defaultExportHandler = new DefaultExportHandler();
    defaultExportHandler.setConverters(converterMap);
    defaultExportHandler.setRepository(repo);
    loginAsRepositoryAdmin();
    ITenant systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminAuthorityName });
    login(sysAdminUserName, systemTenant, new String[] { adminAuthorityName, authenticatedAuthorityName });
    ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(mainTenant_1, "admin", "password", "", new String[] { adminAuthorityName });
    try {
        login("admin", mainTenant_1, new String[] { authenticatedAuthorityName, adminAuthorityName });
        mp.defineInstance(IUnifiedRepository.class, repo);
        mp.defineInstance(DefaultExportHandler.class, defaultExportHandler);
        final String fileName = "file.txt";
        createTestFile("/public".replaceAll("/", ":") + ":" + fileName, text);
        // test download of file
        WebResource webResource = resource();
        webResource.path("repo/files/public:file.txt/download").get(ClientResponse.class);
        // test download of dir as a zip file
        ClientResponse r2 = webResource.path("repo/files/public:file.txt/download").get(ClientResponse.class);
        assertResponse(r2, Status.OK);
        JerseyTestUtil.assertResponseIsZip(r2);
    } catch (Throwable ex) {
        TestCase.fail();
    } finally {
        cleanupUserAndRoles(mainTenant_1);
        cleanupUserAndRoles(systemTenant);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ITenant(org.pentaho.platform.api.mt.ITenant) HashMap(java.util.HashMap) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) Converter(org.pentaho.platform.api.repository2.unified.Converter) WebResource(com.sun.jersey.api.client.WebResource) DefaultExportHandler(org.pentaho.platform.plugin.services.importexport.DefaultExportHandler) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Example 27 with ITenant

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

the class FileResourceIT method testDeleteFiles.

@Test
public void testDeleteFiles() {
    loginAsRepositoryAdmin();
    ITenant systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminAuthorityName });
    ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(mainTenant_1, "admin", "password", "", new String[] { adminAuthorityName });
    try {
        login("admin", mainTenant_1, new String[] { authenticatedAuthorityName });
        String testFile1Id = "abc.txt";
        String testFile2Id = "def.txt";
        // set object in PentahoSystem
        mp.defineInstance(IUnifiedRepository.class, repo);
        String publicFolderPath = ClientRepositoryPaths.getPublicFolderPath();
        createTestFile(publicFolderPath.replaceAll("/", ":") + ":" + testFile1Id, "abcdefg");
        createTestFile(publicFolderPath.replaceAll("/", ":") + ":" + testFile2Id, "abcdefg");
        createTestFolder(":home:admin");
        RepositoryFile file1 = repo.getFile(publicFolderPath + "/" + testFile1Id);
        RepositoryFile file2 = repo.getFile(publicFolderPath + "/" + testFile2Id);
        WebResource webResource = resource();
        webResource.path("repo/files/delete").entity(file1.getId() + "," + file2.getId()).put();
        RepositoryFileDto[] deletedFiles = webResource.path("repo/files/deleted").accept(APPLICATION_XML).get(RepositoryFileDto[].class);
        assertEquals(2, deletedFiles.length);
        webResource.path("repo/files/deletepermanent").entity(file2.getId()).put();
    } catch (Throwable ex) {
        TestCase.fail();
    } finally {
        cleanupUserAndRoles(mainTenant_1);
        cleanupUserAndRoles(systemTenant);
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) ITenant(org.pentaho.platform.api.mt.ITenant) WebResource(com.sun.jersey.api.client.WebResource) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Example 28 with ITenant

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

the class UserRoleDaoService method removeRolesFromUser.

public void removeRolesFromUser(String userName, String roleNames) throws NotFoundException, UncategorizedUserRoleDaoException, SecurityException {
    if (canAdminister()) {
        StringTokenizer tokenizer = new StringTokenizer(roleNames, "\t");
        Set<String> assignedRoles = new HashSet<>();
        ITenant tenant = TenantUtils.getCurrentTenant();
        for (IPentahoRole pentahoRole : getRoleDao().getUserRoles(tenant, userName)) {
            assignedRoles.add(pentahoRole.getName());
        }
        while (tokenizer.hasMoreTokens()) {
            assignedRoles.remove(tokenizer.nextToken());
        }
        getRoleDao().setUserRoles(tenant, userName, assignedRoles.toArray(new String[assignedRoles.size()]));
    } else {
        throw new SecurityException();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) HashSet(java.util.HashSet)

Example 29 with ITenant

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

the class JdbcUserRoleListServiceTest method testGetAllAuthoritiesForTenant.

@Test
public void testGetAllAuthoritiesForTenant() throws Exception {
    ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
    login("admin", defaultTenant);
    JdbcUserRoleListService dao = makePopulatedJdbcUserRoleListService();
    // $NON-NLS-1$
    dao.setAllAuthoritiesQuery("SELECT DISTINCT(AUTHORITY) AS AUTHORITY FROM AUTHORITIES ORDER BY 1");
    dao.afterPropertiesSet();
    List<String> auths = dao.getAllRoles(defaultTenant);
    // $NON-NLS-1$
    assertTrue("Authorities list should not be empty", auths.size() > 0);
    for (String auth : auths) {
        // $NON-NLS-1$
        System.out.println("Authority: " + auth);
    }
    try {
        auths = dao.getAllRoles(new Tenant("/pentaho", true));
    } catch (UnsupportedOperationException uoe) {
        assertNotNull(uoe);
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) JdbcUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService) Test(org.junit.Test)

Example 30 with ITenant

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

the class JdbcUserRoleListServiceTest method testGetAllUsernamesForTenant.

@Test
public void testGetAllUsernamesForTenant() throws Exception {
    ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
    login("admin", defaultTenant);
    JdbcUserRoleListService dao = makePopulatedJdbcUserRoleListService();
    // $NON-NLS-1$
    dao.setAllUsernamesQuery("SELECT DISTINCT(USERNAME) FROM USERS ORDER BY USERNAME");
    dao.afterPropertiesSet();
    List<String> allUsers = dao.getAllUsers(defaultTenant);
    // $NON-NLS-1$
    assertTrue("User List should not be empty", allUsers.size() > 0);
    for (String username : allUsers) {
        // $NON-NLS-1$
        System.out.println("User: " + username);
    }
    try {
        allUsers = dao.getAllUsers(new Tenant("/pentaho", true));
    } catch (UnsupportedOperationException uoe) {
        assertNotNull(uoe);
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) JdbcUserRoleListService(org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService) 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