use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class RepositoryTenantManager method createTenantFolder.
private RepositoryFile createTenantFolder(final ITenant parentTenant, final String tenantName, final String tenantCreatorId) {
return (RepositoryFile) jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException {
Tenant tenant = null;
RepositoryFile parentFolder = null;
if (parentTenant == null) {
tenant = new Tenant("/" + tenantName, true);
} else {
tenant = new Tenant(parentTenant.getRootFolderAbsolutePath() + "/" + tenantName, true);
String folderPath = parentTenant.getRootFolderAbsolutePath();
parentFolder = repositoryFileDao.getFileByAbsolutePath(folderPath);
}
RepositoryFileAcl acl = new RepositoryFileAcl.Builder(tenantCreatorId).entriesInheriting(false).build();
RepositoryFile systemTenantFolder = repositoryFileDao.createFolder(parentFolder != null ? parentFolder.getId() : null, new RepositoryFile.Builder(tenant.getName()).folder(true).build(), acl, "");
repositoryFileDao.getFileByAbsolutePath(tenant.getId());
Map<String, Serializable> fileMeta = repositoryFileDao.getFileMetadata(systemTenantFolder.getId());
fileMeta.put(ITenantManager.TENANT_ROOT, true);
fileMeta.put(ITenantManager.TENANT_ENABLED, true);
JcrRepositoryFileUtils.setFileMetadata(session, systemTenantFolder.getId(), fileMeta);
createRuntimeRolesFolderNode(session, new PentahoJcrConstants(session), tenant);
return systemTenantFolder;
}
});
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class RepositoryTenantManager method createTenant.
/*
* (non-Javadoc)
*
* @see org.pentaho.platform.api.repository2.unified.ITenantManager#createTenant(java.lang.String,
* java.lang.String)
*/
@Override
public ITenant createTenant(final ITenant parentTenant, final String tenantName, final String tenantAdminRoleName, final String authenticatedRoleName, final String anonymousRoleName) {
Tenant newTenant;
String parentTenantFolder;
if (parentTenant == null) {
if (repositoryFileDao.getFileByAbsolutePath("/" + tenantName) != null) {
return null;
}
} else {
if (repositoryFileDao.getFileByAbsolutePath(parentTenant.getRootFolderAbsolutePath() + "/" + tenantName) != null) {
return null;
}
}
if (parentTenant == null) {
newTenant = new Tenant(RepositoryFile.SEPARATOR + tenantName, true);
parentTenantFolder = "/";
} else {
newTenant = new Tenant(parentTenant.getRootFolderAbsolutePath() + RepositoryFile.SEPARATOR + tenantName, true);
parentTenantFolder = parentTenant.getRootFolderAbsolutePath();
}
String tenantCreatorId = PentahoSessionHolder.getSession().getName();
RepositoryFile tenantRootFolder = createTenantFolder(parentTenant, tenantName, tenantCreatorId);
userRoleDao.createRole(newTenant, tenantAdminRoleName, "", new String[0]);
userRoleDao.createRole(newTenant, authenticatedRoleName, "", new String[0]);
userRoleDao.createRole(newTenant, anonymousRoleName, "", new String[0]);
roleBindingDao.setRoleBindings(newTenant, authenticatedRoleName, singleTenantAuthenticatedAuthorityRoleBindingList);
String tenantAdminRoleId = tenantedRoleNameResolver.getPrincipleId(newTenant, tenantAdminRoleName);
RepositoryFileSid tenantAdminRoleSid = new RepositoryFileSid(tenantAdminRoleId, Type.ROLE);
this.jcrTemplate.save();
// tenant admin permissions on the root folder.
if (parentTenant == null) {
repositoryFileAclDao.addAce(tenantRootFolder.getId(), tenantAdminRoleSid, EnumSet.of(RepositoryFilePermission.ALL));
} else {
RepositoryFileAcl acl = repositoryFileAclDao.getAcl(tenantRootFolder.getId());
Builder aclBuilder = new RepositoryFileAcl.Builder(acl).ace(tenantAdminRoleSid, EnumSet.of(RepositoryFilePermission.ALL));
IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication();
login(repositoryAdminUsername, tenantAdminRoleId);
try {
// Give all to Tenant Admin of all ancestors
while (!parentTenantFolder.equals("/")) {
ITenant tenant = new Tenant(parentTenantFolder, true);
String parentTenantAdminRoleId = tenantedRoleNameResolver.getPrincipleId(tenant, tenantAdminRoleName);
RepositoryFileSid parentTenantAdminSid = new RepositoryFileSid(parentTenantAdminRoleId, Type.ROLE);
aclBuilder.ace(parentTenantAdminSid, EnumSet.of(RepositoryFilePermission.ALL));
parentTenantFolder = FilenameUtils.getFullPathNoEndSeparator(parentTenantFolder);
}
repositoryFileAclDao.updateAcl(aclBuilder.build());
} catch (Throwable th) {
th.printStackTrace();
} finally {
PentahoSessionHolder.setSession(origPentahoSession);
SecurityContextHolder.getContext().setAuthentication(origAuthentication);
}
}
try {
RepositoryFileSid fileOwnerSid = new RepositoryFileSid(tenantCreatorId);
createInitialTenantFolders(newTenant, tenantRootFolder, fileOwnerSid);
} catch (Exception ex) {
throw new RuntimeException("Error creating initial tenant folders", ex);
}
return newTenant;
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DirectoryResourceIT method testCreateDir_RootLevel.
@Test
public void testCreateDir_RootLevel() {
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 });
// set object in PentahoSystem
mp.defineInstance(IUnifiedRepository.class, repo);
WebResource webResource = resource();
String rootLevelDirPathId = ":testRootLevelDir";
// Create duplicate directory. FORBIDDEN (403) is expected.
try {
webResource.path("repo/dirs/" + rootLevelDirPathId).put();
fail("FORBIDDEN is expected");
} catch (UniformInterfaceException e) {
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), e.getResponse().getStatus());
}
} catch (AssertionError assertion) {
throw assertion;
} catch (Throwable ex) {
TestCase.fail(ex.getMessage());
} finally {
cleanupUserAndRoles(mainTenant_1);
cleanupUserAndRoles(systemTenant);
logout();
}
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DirectoryResourceIT method testCreateDir.
@Test
public void testCreateDir() {
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 });
// set object in PentahoSystem
mp.defineInstance(IUnifiedRepository.class, repo);
WebResource webResource = resource();
String publicFolderPath = ClientRepositoryPaths.getPublicFolderPath();
String newDirPathId = publicFolderPath.replaceAll("/", ":") + ":testDir";
// Create directory. Success is expected.
webResource.path("repo/dirs/" + newDirPathId).put();
// Create duplicate directory. CONFLICT (409) is expected.
try {
webResource.path("repo/dirs/" + newDirPathId).put();
fail("CONFLICT is expected");
} catch (UniformInterfaceException e) {
assertEquals(Response.Status.CONFLICT.getStatusCode(), e.getResponse().getStatus());
}
} catch (AssertionError assertion) {
throw assertion;
} catch (Throwable ex) {
TestCase.fail(ex.getMessage());
} finally {
cleanupUserAndRoles(mainTenant_1);
cleanupUserAndRoles(systemTenant);
logout();
}
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DirectoryResourceIT method testCreateDir_ServerError.
@Test
public void testCreateDir_ServerError() {
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 });
// set object in PentahoSystem
mp.defineInstance(IUnifiedRepository.class, repo);
WebResource webResource = resource();
String invalidPathId = "/////";
// Invalid path id. INTERNAL_SERVER_ERROR (500) is expected.
try {
webResource.path("repo/dirs/" + invalidPathId).put();
fail("INTERNAL_SERVER_ERROR is expected");
} catch (UniformInterfaceException e) {
assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getResponse().getStatus());
}
} catch (AssertionError assertion) {
throw assertion;
} catch (Throwable ex) {
TestCase.fail(ex.getMessage());
} finally {
cleanupUserAndRoles(mainTenant_1);
cleanupUserAndRoles(systemTenant);
logout();
}
}
Aggregations