use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method internalUpdateFile.
private RepositoryFile internalUpdateFile(final Session session, final PentahoJcrConstants pentahoJcrConstants, final RepositoryFile file, final IRepositoryFileData content, final String versionMessage) throws RepositoryException {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
Assert.notNull(file);
Assert.isTrue(!file.isFolder());
Assert.notNull(content);
// Get repository file info and acl info of parent
RepositoryFileAcl acl = aclDao.getAcl(file.getId());
// Invoke accessVoterManager to see if we have access to perform this operation
if (!accessVoterManager.hasAccess(file, RepositoryFilePermission.WRITE, acl, PentahoSessionHolder.getSession())) {
return null;
}
lockHelper.addLockTokenToSessionIfNecessary(session, pentahoJcrConstants, file.getId());
JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, file.getId());
JcrRepositoryFileUtils.updateFileNode(session, pentahoJcrConstants, file, content, findTransformerForWrite(content.getClass()));
session.save();
JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, file.getId(), versionMessage, file.getCreatedDate() != null ? file.getCreatedDate() : new java.util.Date(), true);
lockHelper.removeLockTokenFromSessionIfNecessary(session, pentahoJcrConstants, file.getId());
return JcrRepositoryFileUtils.nodeIdToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, file.getId());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method deleteFile.
/**
* {@inheritDoc}
*/
@Override
public void deleteFile(final Serializable fileId, final String versionMessage) {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
Assert.notNull(fileId);
jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
RepositoryFile fileToBeDeleted = getFileById(fileId);
// Get repository file info and acl info of parent
if (fileToBeDeleted != null) {
RepositoryFileAcl toBeDeletedFileAcl = aclDao.getAcl(fileToBeDeleted.getId());
// Invoke accessVoterManager to see if we have access to perform this operation
if (!accessVoterManager.hasAccess(fileToBeDeleted, RepositoryFilePermission.DELETE, toBeDeletedFileAcl, PentahoSessionHolder.getSession())) {
return null;
}
}
List<RepositoryFilePermission> perms = new ArrayList<RepositoryFilePermission>();
perms.add(RepositoryFilePermission.DELETE);
if (!aclDao.hasAccess(fileToBeDeleted.getPath(), EnumSet.copyOf(perms))) {
throw new AccessDeniedException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED_DELETE", fileId));
}
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
Serializable parentFolderId = JcrRepositoryFileUtils.getParentId(session, fileId);
JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId);
deleteHelper.deleteFile(session, pentahoJcrConstants, fileId);
session.save();
JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId, versionMessage);
return null;
}
});
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method createFolder.
public RepositoryFile createFolder(Serializable parentFolderId, RepositoryFile file, RepositoryFileAcl acl, String versionMessage) {
try {
String folderNameWithPath = parentFolderId + "/" + file.getName();
File newFolder = new File(folderNameWithPath);
newFolder.mkdir();
final RepositoryFile repositoryFolder = internalGetFile(newFolder);
return repositoryFolder;
} catch (Throwable th) {
throw new UnifiedRepositoryException();
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class JcrRepositoryFileUtils method checkNodeForTree.
/**
* This method is called twice by <code>getTreeNode</code>. It's job is to determine whether the current child node
* should be added to the list of children for the node being processed. It is a separate method simply because it is
* too much code to appear twice in the above <code>getTreeNode</code> method. It also makes the recursive call back
* to getTreeByNode to process the next lower level of folder node (it must process the lower levels to know if the
* folder should be added). Finally, it returns the foundFiltered boolean to let the caller know if a file was found
* that satisfied the childNodeFilter.
*/
static void checkNodeForTree(final Node childNode, List<RepositoryFileTree> children, final Session session, final PentahoJcrConstants pentahoJcrConstants, final IPathConversionHelper pathConversionHelper, final String childNodeFilter, final ILockHelper lockHelper, final int depth, final boolean showHidden, final IRepositoryAccessVoterManager accessVoterManager, RepositoryRequest.FILES_TYPE_FILTER types, MutableBoolean foundFiltered, boolean isRootFiltered, final boolean includeSystemFolders, final String rootPath) throws RepositoryException {
RepositoryFile file = nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, childNode);
if (isSupportedNodeType(pentahoJcrConstants, childNode)) {
RepositoryFileAcl fileAcl;
try {
fileAcl = JcrRepositoryFileAclUtils.getAcl(session, pentahoJcrConstants, file.getId());
} catch (AccessDeniedException e) {
return;
}
if (accessVoterManager.hasAccess(file, RepositoryFilePermission.READ, fileAcl, PentahoSessionHolder.getSession())) {
MutableBoolean foundFilteredAtomic = new MutableBoolean(!isPentahoFolder(pentahoJcrConstants, childNode));
RepositoryFileTree repositoryFileTree = getTreeByNode(session, pentahoJcrConstants, pathConversionHelper, lockHelper, childNode, depth - 1, childNodeFilter, showHidden, accessVoterManager, types, foundFilteredAtomic, includeSystemFolders, rootPath);
if (repositoryFileTree != null && (foundFilteredAtomic.booleanValue() || isRootFiltered)) {
foundFiltered.setValue(true);
children.add(repositoryFileTree);
}
}
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl 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;
}
});
}
Aggregations