use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method permanentlyDeleteFile.
/**
* {@inheritDoc}
* <p/>
* <p>
* No checkout needed as .trash is not versioned.
* </p>
*/
@Override
public void permanentlyDeleteFile(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;
}
}
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
deleteHelper.permanentlyDeleteFile(session, pentahoJcrConstants, fileId);
session.save();
return null;
}
});
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method deleteFileAtVersion.
/**
* {@inheritDoc}
*/
@Override
public void deleteFileAtVersion(final Serializable fileId, final Serializable versionId) {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
Assert.notNull(fileId);
Assert.notNull(versionId);
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;
}
}
Node fileToDeleteNode = session.getNodeByIdentifier(fileId.toString());
session.getWorkspace().getVersionManager().getVersionHistory(fileToDeleteNode.getPath()).removeVersion(versionId.toString());
session.save();
return null;
}
});
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method internalGetFile.
private RepositoryFile internalGetFile(final Session session, final String absPath, final boolean loadMaps, final IPentahoLocale locale) throws RepositoryException {
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
Item fileNode;
try {
fileNode = session.getItem(JcrStringHelper.pathEncode(absPath));
// items are nodes or properties; this must be a node
Assert.isTrue(fileNode.isNode());
} catch (PathNotFoundException e) {
fileNode = null;
}
RepositoryFile file = fileNode != null ? JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, (Node) fileNode, loadMaps, locale) : null;
if (file != null) {
RepositoryFileAcl acl = aclDao.getAcl(file.getId());
// Invoke accessVoterManager to see if we have access to perform this operation
if (!accessVoterManager.hasAccess(file, RepositoryFilePermission.READ, acl, PentahoSessionHolder.getSession())) {
return null;
}
}
return file;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method internalCreateFolder.
// ~ Methods
// =========================================================================================================
private RepositoryFile internalCreateFolder(final Session session, final Serializable parentFolderId, final RepositoryFile folder, final RepositoryFileAcl acl, final String versionMessage) throws RepositoryException {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
// Get repository file info and acl info of parent
if (parentFolderId != null) {
RepositoryFile parentRepositoryFile = getFileById(parentFolderId);
if (parentRepositoryFile != null) {
RepositoryFileAcl parentAcl = aclDao.getAcl(parentRepositoryFile.getId());
// Invoke accessVoterManager to see if we have access to perform this operation
if (!accessVoterManager.hasAccess(parentRepositoryFile, RepositoryFilePermission.WRITE, parentAcl, PentahoSessionHolder.getSession())) {
return null;
}
}
}
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId);
Node folderNode = JcrRepositoryFileUtils.createFolderNode(session, pentahoJcrConstants, parentFolderId, folder);
// create a temporary folder object with correct path for default acl purposes.
String path = JcrRepositoryFileUtils.getAbsolutePath(session, pentahoJcrConstants, folderNode);
RepositoryFile tmpFolder = new RepositoryFile.Builder(folder).path(path).build();
// we must create the acl during checkout
JcrRepositoryFileAclUtils.createAcl(session, pentahoJcrConstants, folderNode.getIdentifier(), acl == null ? defaultAclHandler.createDefaultAcl(tmpFolder) : acl);
session.save();
if (folder.isVersioned()) {
JcrRepositoryFileUtils.checkinNearestVersionableNodeIfNecessary(session, pentahoJcrConstants, folderNode, versionMessage);
}
JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId, Messages.getInstance().getString("JcrRepositoryFileDao.USER_0001_VER_COMMENT_ADD_FOLDER", folder.getName(), // $NON-NLS-1$ //$NON-NLS-2$
(parentFolderId == null ? "root" : parentFolderId.toString())));
return JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, folderNode);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class FileSystemRepositoryFileDao method createFile.
public RepositoryFile createFile(Serializable parentFolderId, RepositoryFile file, IRepositoryFileData data, RepositoryFileAcl acl, String versionMessage) {
String fileNameWithPath = RepositoryFilenameUtils.concat(parentFolderId.toString(), file.getName());
FileOutputStream fos = null;
File f = new File(fileNameWithPath);
try {
f.createNewFile();
fos = new FileOutputStream(f);
if (data instanceof SimpleRepositoryFileData) {
fos.write(inputStreamToBytes(((SimpleRepositoryFileData) data).getInputStream()));
} else if (data instanceof NodeRepositoryFileData) {
fos.write(inputStreamToBytes(new ByteArrayInputStream(((NodeRepositoryFileData) data).getNode().toString().getBytes())));
}
} catch (FileNotFoundException e) {
throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e);
} catch (IOException e) {
throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e);
} finally {
IOUtils.closeQuietly(fos);
}
return internalGetFile(f);
}
Aggregations