use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-kettle by pentaho.
the class UIEERepositoryDirectoryIT method createUserHomeFolder.
private void createUserHomeFolder(final ITenant theTenant, final String theUsername) {
IPentahoSession origPentahoSession = PentahoSessionHolder.getSession();
Authentication origAuthentication = SecurityContextHolder.getContext().getAuthentication();
StandaloneSession pentahoSession = new StandaloneSession(repositoryAdminUsername);
pentahoSession.setAuthenticated(null, repositoryAdminUsername);
PentahoSessionHolder.setSession(pentahoSession);
try {
txnTemplate.execute(new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult(final TransactionStatus status) {
Builder aclsForUserHomeFolder = null;
Builder aclsForTenantHomeFolder = null;
ITenant tenant = null;
String username = null;
if (theTenant == null) {
tenant = getTenant(username, true);
username = getPrincipalName(theUsername, true);
} else {
tenant = theTenant;
username = theUsername;
}
if (tenant == null || tenant.getId() == null) {
tenant = getCurrentTenant();
}
if (tenant == null || tenant.getId() == null) {
tenant = JcrTenantUtils.getDefaultTenant();
}
RepositoryFile userHomeFolder = null;
String userId = userNameUtils.getPrincipleId(theTenant, username);
final RepositoryFileSid userSid = new RepositoryFileSid(userId);
RepositoryFile tenantHomeFolder = null;
RepositoryFile tenantRootFolder = null;
// Get the Tenant Root folder. If the Tenant Root folder does not exist then exit.
tenantRootFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getTenantRootFolderPath(theTenant));
if (tenantRootFolder != null) {
// Try to see if Tenant Home folder exist
tenantHomeFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getTenantHomeFolderPath(theTenant));
if (tenantHomeFolder == null) {
String ownerId = userNameUtils.getPrincipleId(theTenant, username);
RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, Type.USER);
String tenantAuthenticatedRoleId = roleNameUtils.getPrincipleId(theTenant, tenantAuthenticatedRoleName);
RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid(tenantAuthenticatedRoleId, Type.ROLE);
aclsForTenantHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(tenantAuthenticatedRoleSid, EnumSet.of(RepositoryFilePermission.READ));
aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
tenantHomeFolder = repositoryFileDao.createFolder(tenantRootFolder.getId(), new RepositoryFile.Builder(ServerRepositoryPaths.getTenantHomeFolderName()).folder(true).build(), aclsForTenantHomeFolder.build(), "tenant home folder");
} else {
String ownerId = userNameUtils.getPrincipleId(theTenant, username);
RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, Type.USER);
aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
}
// now check if user's home folder exist
userHomeFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getUserHomeFolderPath(theTenant, username));
if (userHomeFolder == null) {
userHomeFolder = repositoryFileDao.createFolder(tenantHomeFolder.getId(), new RepositoryFile.Builder(username).folder(true).build(), aclsForUserHomeFolder.build(), // $NON-NLS-1$
"user home folder");
}
}
}
});
} finally {
// Switch our identity back to the original user.
PentahoSessionHolder.setSession(origPentahoSession);
SecurityContextHolder.getContext().setAuthentication(origAuthentication);
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-kettle by pentaho.
the class PurRepositoryMetaStore method getMetaStoreFolders.
private String getMetaStoreFolders(StringBuilder builder, RepositoryFile folder, int level) {
String spaces = Const.rightPad(" ", level * 2);
builder.append(spaces);
if (folder.isFolder()) {
builder.append("/");
}
builder.append(folder.getName()).append(Const.CR);
for (RepositoryFile file : getChildren(folder.getId())) {
getMetaStoreFolders(builder, file, level + 1);
}
return builder.toString();
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.
the class RepositoryFileImportFileHandler method createFolderJustInTime.
public RepositoryFile createFolderJustInTime(String folderPath, String manifestKey) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
// The file doesn't exist and it is a folder. Create folder.
getLogger().trace("Creating implied folder [" + folderPath + "]");
final Serializable parentId = getParentId(folderPath);
Assert.notNull(parentId);
boolean isHidden;
if (getImportSession().isFileHidden(manifestKey) == null) {
isHidden = false;
} else {
isHidden = getImportSession().isFileHidden(manifestKey);
}
RepositoryFile.Builder builder = new RepositoryFile.Builder(RepositoryFilenameUtils.getName(folderPath)).path(RepositoryFilenameUtils.getPath(folderPath)).folder(true).hidden(isHidden);
RepositoryFile repoFile = builder.build();
RepositoryFileAcl repoAcl = getImportSession().processAclForFile(manifestKey);
if (repoAcl != null) {
repoFile = repository.createFolder(parentId, repoFile, repoAcl, null);
RepositoryFileAcl repositoryFileAcl = null;
try {
repositoryFileAcl = getImportSession().getManifest().getExportManifestEntity(manifestKey).getRepositoryFileAcl();
} catch (NullPointerException e) {
// If npe then manifest entry is not defined which is likely so just ignore
} catch (ExportManifestFormatException e) {
// Same goes here
}
updateAcl(true, repoFile, repositoryFileAcl);
} else {
repoFile = repository.createFolder(parentId, repoFile, null);
}
getImportSession().getFoldersCreatedImplicitly().add(folderPath);
return repoFile;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.
the class AbstractRepositoryTenantManager method createUserHomeFolder.
@Override
public RepositoryFile createUserHomeFolder(ITenant theTenant, String username) {
Builder aclsForUserHomeFolder = null;
Builder aclsForTenantHomeFolder = null;
RepositoryFile userHomeFolder = null;
RepositoryFile tenantHomeFolder = null;
RepositoryFile tenantRootFolder = null;
String userId = tenantedUserNameResolver.getPrincipleId(theTenant, username);
final RepositoryFileSid userSid = new RepositoryFileSid(userId);
username = JcrTenantUtils.getPrincipalName(username, true);
if (theTenant == null) {
theTenant = JcrTenantUtils.getTenant(username, true);
}
// Get the Tenant Root folder. If the Tenant Root folder does not exist then exit.
tenantRootFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getTenantRootFolderPath(theTenant));
if (tenantRootFolder != null) {
// Try to see if Tenant Home folder exist
tenantHomeFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getTenantHomeFolderPath(theTenant));
if (tenantHomeFolder == null) {
String ownerId = tenantedUserNameResolver.getPrincipleId(theTenant, username);
RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, Type.USER);
String tenantAuthenticatedRoleId = tenantedRoleNameResolver.getPrincipleId(theTenant, tenantAuthenticatedRoleName);
RepositoryFileSid tenantAuthenticatedRoleSid = new RepositoryFileSid(tenantAuthenticatedRoleId, Type.ROLE);
aclsForTenantHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(tenantAuthenticatedRoleSid, EnumSet.of(RepositoryFilePermission.READ));
aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
tenantHomeFolder = repositoryFileDao.createFolder(tenantRootFolder.getId(), new RepositoryFile.Builder(ServerRepositoryPaths.getTenantHomeFolderName()).folder(true).build(), aclsForTenantHomeFolder.build(), "tenant home folder");
} else {
String ownerId = tenantedUserNameResolver.getPrincipleId(theTenant, username);
RepositoryFileSid ownerSid = new RepositoryFileSid(ownerId, Type.USER);
aclsForUserHomeFolder = new RepositoryFileAcl.Builder(userSid).ace(ownerSid, EnumSet.of(RepositoryFilePermission.ALL));
}
// now check if user's home folder exist
userHomeFolder = repositoryFileDao.getFileByAbsolutePath(ServerRepositoryPaths.getUserHomeFolderPath(theTenant, username));
if (userHomeFolder == null) {
userHomeFolder = repositoryFileDao.createFolder(tenantHomeFolder.getId(), new RepositoryFile.Builder(username).folder(true).build(), aclsForUserHomeFolder.build(), // $NON-NLS-1$
"user home folder");
}
}
return userHomeFolder;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder 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;
}
Aggregations