Search in sources :

Example 6 with PentahoJcrConstants

use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.

the class JcrRepositoryFileAclDao method internalUpdateAcl.

protected RepositoryFileAcl internalUpdateAcl(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId, final RepositoryFileAcl acl) throws RepositoryException {
    if (isKioskEnabled()) {
        // $NON-NLS-1$
        throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
    }
    DefaultPermissionConversionHelper permissionConversionHelper = new DefaultPermissionConversionHelper(session);
    Node node = session.getNodeByIdentifier(fileId.toString());
    if (node == null) {
        throw new RepositoryException(Messages.getInstance().getString("JackrabbitRepositoryFileAclDao.ERROR_0001_NODE_NOT_FOUND", // $NON-NLS-1$
        fileId.toString()));
    }
    String absPath = node.getPath();
    AccessControlManager acMgr = session.getAccessControlManager();
    AccessControlList acList = getAccessControlList(acMgr, absPath);
    // clear all entries
    AccessControlEntry[] acEntries = acList.getAccessControlEntries();
    for (int i = 0; i < acEntries.length; i++) {
        acList.removeAccessControlEntry(acEntries[i]);
    }
    JcrRepositoryFileAclUtils.setAclMetadata(session, absPath, acList, new AclMetadata(acl.getOwner().getName(), acl.isEntriesInheriting()));
    // add entries to now empty list but only if not inheriting; force user to start with clean slate
    boolean adminPrincipalExist = false;
    ITenant principalTenant = null;
    if (!acl.isEntriesInheriting()) {
        for (RepositoryFileAce ace : acl.getAces()) {
            Principal principal = null;
            if (RepositoryFileSid.Type.ROLE == ace.getSid().getType()) {
                String principalName = JcrTenantUtils.getRoleNameUtils().getPrincipleName(ace.getSid().getName());
                if (tenantAdminAuthorityName.equals(principalName)) {
                    adminPrincipalExist = true;
                }
                principal = new SpringSecurityRolePrincipal(JcrTenantUtils.getTenantedRole(ace.getSid().getName()));
            } else {
                principal = new SpringSecurityUserPrincipal(JcrTenantUtils.getTenantedUser(ace.getSid().getName()));
            }
            acList.addAccessControlEntry(principal, permissionConversionHelper.pentahoPermissionsToPrivileges(session, ace.getPermissions()));
        }
        if (!adminPrincipalExist) {
            if (acl.getAces() != null && acl.getAces().size() > 0) {
                principalTenant = JcrTenantUtils.getRoleNameUtils().getTenant(acl.getAces().get(0).getSid().getName());
            }
            if (principalTenant == null || principalTenant.getId() == null) {
                principalTenant = JcrTenantUtils.getTenant();
            }
            List<RepositoryFilePermission> permissionList = new ArrayList<RepositoryFilePermission>();
            permissionList.add(RepositoryFilePermission.ALL);
            Principal adminPrincipal = new SpringSecurityRolePrincipal(JcrTenantUtils.getRoleNameUtils().getPrincipleId(principalTenant, tenantAdminAuthorityName));
            acList.addAccessControlEntry(adminPrincipal, permissionConversionHelper.pentahoPermissionsToPrivileges(session, EnumSet.copyOf(permissionList)));
        }
    }
    acMgr.setPolicy(absPath, acList);
    session.save();
    return getAcl(fileId);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce) Node(javax.jcr.Node) AclMetadata(org.pentaho.platform.repository2.unified.jcr.IAclMetadataStrategy.AclMetadata) ArrayList(java.util.ArrayList) AccessControlEntry(javax.jcr.security.AccessControlEntry) RepositoryException(javax.jcr.RepositoryException) ITenant(org.pentaho.platform.api.mt.ITenant) SpringSecurityRolePrincipal(org.pentaho.platform.repository2.unified.jcr.jackrabbit.security.SpringSecurityRolePrincipal) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) SpringSecurityRolePrincipal(org.pentaho.platform.repository2.unified.jcr.jackrabbit.security.SpringSecurityRolePrincipal) SpringSecurityUserPrincipal(org.pentaho.platform.repository2.unified.jcr.jackrabbit.security.SpringSecurityUserPrincipal) Principal(java.security.Principal) SpringSecurityUserPrincipal(org.pentaho.platform.repository2.unified.jcr.jackrabbit.security.SpringSecurityUserPrincipal)

Example 7 with PentahoJcrConstants

use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.

the class DefaultDeleteHelper method permanentlyDeleteFile.

/**
 * {@inheritDoc}
 */
public void permanentlyDeleteFile(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) throws RepositoryException {
    Assert.notNull(fileId);
    Node fileNode = session.getNodeByIdentifier(fileId.toString());
    // guard against using a file retrieved from a more lenient session inside a more strict session
    Assert.notNull(fileNode);
    // see if anything is referencing this node; if yes, then we cannot delete it as a
    // ReferentialIntegrityException
    // will result
    Set<RepositoryFile> referrers = new HashSet<RepositoryFile>();
    PropertyIterator refIter = fileNode.getReferences();
    if (refIter.hasNext()) {
        while (refIter.hasNext()) {
            // for each referrer property, march up the tree until we find the file node to which the property belongs
            RepositoryFile referrer = getReferrerFile(session, pentahoJcrConstants, refIter.nextProperty());
            if (referrer != null) {
                referrers.add(referrer);
            }
        }
        if (!referrers.isEmpty()) {
            RepositoryFile referee = JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, fileNode);
            throw new RepositoryFileDaoReferentialIntegrityException(referee, referrers);
        }
    }
    // it first
    if (fileNode.isLocked()) {
        Lock lock = session.getWorkspace().getLockManager().getLock(fileNode.getPath());
        // don't need lock token anymore
        lockHelper.removeLockToken(session, pentahoJcrConstants, lock);
    }
    // if this file was non-permanently deleted, delete its containing folder too
    IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
    String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
    String trashFolder = ServerRepositoryPaths.getUserHomeFolderPath(new Tenant(tenantId, true), PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + FOLDER_NAME_TRASH;
    Node parent = fileNode.getParent();
    purgeHistory(fileNode, session, pentahoJcrConstants);
    if (fileNode.getPath().startsWith(trashFolder)) {
        // Remove the file and then the wrapper foler
        fileNode.remove();
        parent.remove();
    } else {
        fileNode.remove();
    }
}
Also used : Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) RepositoryFileDaoReferentialIntegrityException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) HashSet(java.util.HashSet) Lock(javax.jcr.lock.Lock)

Example 8 with PentahoJcrConstants

use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.

the class DefaultDeleteHelper method undeleteFile.

/**
 * {@inheritDoc}
 */
public void undeleteFile(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) throws RepositoryException {
    Node fileToUndeleteNode = session.getNodeByIdentifier(fileId.toString());
    String trashFileIdNodePath = fileToUndeleteNode.getParent().getPath();
    String origParentFolderPath = getOriginalParentFolderPath(session, pentahoJcrConstants, fileToUndeleteNode, false);
    String absDestPath = origParentFolderPath + RepositoryFile.SEPARATOR + fileToUndeleteNode.getName();
    if (session.itemExists(absDestPath)) {
        RepositoryFile file = JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, (Node) session.getItem(absDestPath));
        throw new RepositoryFileDaoFileExistsException(file);
    }
    session.move(fileToUndeleteNode.getPath(), absDestPath);
    session.getItem(trashFileIdNodePath).remove();
}
Also used : RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) Node(javax.jcr.Node) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 9 with PentahoJcrConstants

use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.

the class AbstractRepositoryTenantManager method getChildTenants.

public List<ITenant> getChildTenants(Session session, final ITenant parentTenant, final boolean includeDisabledTenants) throws RepositoryException {
    List<ITenant> children = new ArrayList<ITenant>();
    List<RepositoryFile> allChildren = JcrRepositoryFileUtils.getChildren(session, new PentahoJcrConstants(session), pathConversionHelper, null, getTenantRootFolder(session, parentTenant).getId(), null);
    for (RepositoryFile repoFile : allChildren) {
        Map<String, Serializable> metadata = JcrRepositoryFileUtils.getFileMetadata(session, repoFile.getId());
        if (metadata.containsKey(ITenantManager.TENANT_ROOT) && (Boolean) metadata.get(ITenantManager.TENANT_ROOT)) {
            Tenant tenant = new Tenant(repoFile.getPath(), isTenantEnabled(session, repoFile.getId()));
            if (includeDisabledTenants || tenant.isEnabled()) {
                children.add(new Tenant(pathConversionHelper.relToAbs(repoFile.getPath()), isTenantEnabled(session, repoFile.getId())));
            }
        }
    }
    return children;
}
Also used : Serializable(java.io.Serializable) ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) PentahoJcrConstants(org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 10 with PentahoJcrConstants

use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants 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

Node (javax.jcr.Node)15 RepositoryException (javax.jcr.RepositoryException)9 PentahoJcrConstants (org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants)9 RepositoryFileDaoFileExistsException (org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException)7 RepositoryFileDaoReferentialIntegrityException (org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Matchers.anyString (org.mockito.Matchers.anyString)6 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)6 Property (javax.jcr.Property)5 Workspace (javax.jcr.Workspace)5 Serializable (java.io.Serializable)4 NodeIterator (javax.jcr.NodeIterator)4 PropertyIterator (javax.jcr.PropertyIterator)4 Session (javax.jcr.Session)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 ITenant (org.pentaho.platform.api.mt.ITenant)4 Tenant (org.pentaho.platform.core.mt.Tenant)4 JcrCallback (org.springframework.extensions.jcr.JcrCallback)4 Lock (javax.jcr.lock.Lock)3