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);
}
}
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);
}
}
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();
}
}
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);
}
}
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);
}
}
Aggregations