use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class JcrRepositoryFileDaoIT method createFile.
private RepositoryFile createFile(String fileName) 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 parentFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY));
Date oldDate = new Date();
RepositoryFile newFile = createSampleFile(parentFolder.getPath(), fileName, "sdfdf", false, 5, true);
newFile = new RepositoryFile.Builder(newFile).createdDate(oldDate).build();
return newFile;
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class UnifiedRepositoryToWebServiceAdapterIT method testFileMetadata.
@Test
public void testFileMetadata() throws Exception {
login(sysAdminUserName, systemTenant, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAuthenticatedRoleName });
RepositoryFile file = repo.getFile(ClientRepositoryPaths.getPublicFolderPath());
final RepositoryFile testfile = repo.createFile(file.getId(), new RepositoryFile.Builder("testfile").build(), new SimpleRepositoryFileData(new ByteArrayInputStream("test".getBytes()), "UTF-8", "text/plain"), null);
// CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
{
// Make sure the repository is setup correctly
assertNotNull(testfile);
assertNotNull(testfile.getId());
final Map<String, Serializable> fileMetadata = repo.getFileMetadata(testfile.getId());
assertNotNull(fileMetadata);
assertEquals(1, fileMetadata.size());
}
final Map<String, Serializable> metadata = new HashMap<String, Serializable>();
metadata.put("sample key", "sample value");
metadata.put("complex key?", "\"an even more 'complex' value\"! {and them some}");
adapter.setFileMetadata(testfile.getId(), metadata);
// CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
{
// Make sure the repository sees the metadata
assertNotNull(testfile);
assertNotNull(testfile.getId());
final Map<String, Serializable> fileMetadata = repo.getFileMetadata(testfile.getId());
assertNotNull(fileMetadata);
assertEquals(2, fileMetadata.size());
}
// CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
{
// Make sure we can get the same metadata back via the web service
final Map<String, Serializable> fileMetadata = adapter.getFileMetadata(testfile.getId());
assertNotNull(fileMetadata);
assertEquals(2, fileMetadata.size());
assertTrue(StringUtils.equals("sample value", (String) fileMetadata.get("sample key")));
assertTrue(StringUtils.equals("\"an even more 'complex' value\"! {and them some}", (String) fileMetadata.get("complex key?")));
}
cleanupUserAndRoles(mainTenant_1);
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class RepositoryTenantManagerIT method testCreateTenant.
@Test
public void testCreateTenant() {
loginAsSysTenantAdmin();
assertNotNull(systemTenant);
assertTrue(systemTenant.isEnabled());
ITenant tenantRoot = tenantManager.createTenant(systemTenant, TenantUtils.TENANTID_SINGLE_TENANT, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantRoot, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
assertNotNull(tenantRoot);
assertTrue(tenantRoot.isEnabled());
ITenant subTenantRoot = tenantManager.createTenant(tenantRoot, TENANT_ID_APPLE, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenantRoot, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
assertNotNull(subTenantRoot);
assertTrue(subTenantRoot.isEnabled());
List<ITenant> childTenants = tenantManager.getChildTenants(tenantRoot);
assertTrue(childTenants.size() == 1);
assertTrue(childTenants.get(0).equals(subTenantRoot));
cleanupUserAndRoles(tenantRoot);
cleanupUserAndRoles(subTenantRoot);
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class RepositoryTenantManagerIT method testDeleteTenant.
@Test
public void testDeleteTenant() {
loginAsSysTenantAdmin();
ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
ITenant mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_2, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
ITenant subTenant1_1 = null;
// Testing SubTenant1_1 as a TenantAdmin of MainTenant2. This should fail
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
try {
subTenant1_1 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
fail("should have thrown an exception");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
subTenant1_1 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenant1_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
ITenant subTenant1_1_1 = tenantManager.createTenant(subTenant1_1, SUB_TENANT1_1_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenant1_1_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
ITenant subTenant1_1_2 = tenantManager.createTenant(subTenant1_1, SUB_TENANT1_1_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenant1_1_2, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
logout();
// Testing SubTenant1_2 as a TenantAdmin of MainTenant2. This should fail
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
ITenant subTenant1_2 = null;
try {
subTenant1_2 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
fail("should have thrown an exception");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
subTenant1_2 = tenantManager.createTenant(mainTenant_1, SUB_TENANT1_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenant1_2, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
logout();
login(USERNAME_ADMIN, subTenant1_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
ITenant subTenant1_2_1 = tenantManager.createTenant(subTenant1_2, SUB_TENANT1_2_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenant1_2_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
ITenant subTenant1_2_2 = tenantManager.createTenant(subTenant1_2, SUB_TENANT1_2_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenant1_2_2, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
ITenant subTenant2_1 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenant2_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
ITenant subTenant2_1_1 = tenantManager.createTenant(subTenant2_1, SUB_TENANT2_1_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenant2_1_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
ITenant subTenant2_1_2 = tenantManager.createTenant(subTenant2_1, SUB_TENANT2_1_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenant2_1_2, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
ITenant subTenant2_2 = null;
try {
subTenant2_2 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
fail("should have thrown an exception");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
subTenant2_2 = tenantManager.createTenant(mainTenant_2, SUB_TENANT2_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenant2_2, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
logout();
login(USERNAME_ADMIN, subTenant2_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
ITenant subTenant2_2_1 = tenantManager.createTenant(subTenant2_2, SUB_TENANT2_2_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenant2_2_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
ITenant subTenant2_2_2 = tenantManager.createTenant(subTenant2_2, SUB_TENANT2_2_2, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(subTenant2_2_2, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
// Delete Tenants
login(USERNAME_ADMIN, subTenant2_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
try {
tenantManager.deleteTenant(subTenant2_1);
fail("should have thrown an exception");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
tenantManager.deleteTenant(subTenant2_1);
ITenant tenant = tenantManager.getTenant(subTenant2_1.getRootFolderAbsolutePath());
assertNull(tenant);
tenant = tenantManager.getTenant(subTenant2_1_1.getRootFolderAbsolutePath());
assertNull(tenant);
tenant = tenantManager.getTenant(subTenant2_1_2.getRootFolderAbsolutePath());
assertNull(tenant);
logout();
login(USERNAME_ADMIN, subTenant2_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
try {
tenantManager.deleteTenant(subTenant2_2);
fail("should have thrown an exception");
} catch (Throwable th) {
assertNotNull(th);
}
logout();
login(USERNAME_ADMIN, mainTenant_2, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
tenantManager.deleteTenant(subTenant2_2);
tenant = tenantManager.getTenant(subTenant2_2.getRootFolderAbsolutePath());
assertNull(tenant);
tenant = tenantManager.getTenant(subTenant2_2_1.getRootFolderAbsolutePath());
assertNull(tenant);
tenant = tenantManager.getTenant(subTenant2_2_2.getRootFolderAbsolutePath());
assertNull(tenant);
logout();
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
tenantManager.deleteTenant(subTenant1_1);
tenantManager.deleteTenant(subTenant1_2);
logout();
loginAsSysTenantAdmin();
tenantManager.deleteTenant(mainTenant_1);
tenantManager.deleteTenant(mainTenant_2);
logout();
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class UserRoleDaoUserDetailsServiceIT method testLoadUserByUsernameNoRoles.
@Test
public void testLoadUserByUsernameNoRoles() {
loginAsSysTenantAdmin();
ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(mainTenant_1, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, mainTenant_1, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
IPentahoUser pentahoUser = userRoleDao.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, null);
UserRoleDaoUserDetailsService userDetailsService = new UserRoleDaoUserDetailsService();
userDetailsService.setUserRoleDao(userRoleDao);
try {
userDetailsService.loadUserByUsername(USER_2);
} catch (UsernameNotFoundException unnf) {
assertNotNull(unnf);
}
cleanupUserAndRoles(mainTenant_1);
}
Aggregations