Search in sources :

Example 36 with RepositoryFileAcl

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());
}
Also used : RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 37 with RepositoryFileAcl

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;
        }
    });
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Serializable(java.io.Serializable) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) JcrCallback(org.springframework.extensions.jcr.JcrCallback) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Session(javax.jcr.Session)

Example 38 with RepositoryFileAcl

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();
    }
}
Also used : UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 39 with RepositoryFileAcl

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);
            }
        }
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 40 with RepositoryFileAcl

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;
        }
    });
}
Also used : Serializable(java.io.Serializable) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) PentahoJcrConstants(org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants) Builder(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) JcrCallback(org.springframework.extensions.jcr.JcrCallback) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Session(javax.jcr.Session) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Aggregations

RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)99 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)73 Test (org.junit.Test)50 ITenant (org.pentaho.platform.api.mt.ITenant)25 RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)23 RepositoryFileAce (org.pentaho.platform.api.repository2.unified.RepositoryFileAce)15 Node (javax.jcr.Node)13 Matchers.anyString (org.mockito.Matchers.anyString)13 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)13 Serializable (java.io.Serializable)12 Session (javax.jcr.Session)12 JcrCallback (org.springframework.extensions.jcr.JcrCallback)12 ArrayList (java.util.ArrayList)11 RepositoryException (javax.jcr.RepositoryException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 IOException (java.io.IOException)9 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)9 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)8 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)8 InputStream (java.io.InputStream)7