Search in sources :

Example 6 with Tenant

use of org.pentaho.platform.core.mt.Tenant 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 7 with Tenant

use of org.pentaho.platform.core.mt.Tenant in project pentaho-platform by pentaho.

the class JcrTenantUtils method getTenantedUser.

public static String getTenantedUser(String username) {
    if (username != null && !username.equals(getRepositoryAdminUserName()) && getUserNameUtils() != null) {
        ITenant tenant = getUserNameUtils().getTenant(username);
        if (tenant == null || tenant.getId() == null) {
            IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
            String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
            if (tenantId == null) {
                tenantId = getDefaultTenantPath();
            }
            tenant = new Tenant(tenantId, true);
            return getUserNameUtils().getPrincipleId(tenant, username);
        } else {
            return username;
        }
    } else {
        return username;
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 8 with Tenant

use of org.pentaho.platform.core.mt.Tenant in project pentaho-platform by pentaho.

the class JcrTenantUtils method getTenantedRole.

public static String getTenantedRole(String principal) {
    if (principal != null && !principal.equals("administrators") && getRoleNameUtils() != null) {
        ITenant tenant = getRoleNameUtils().getTenant(principal);
        if (tenant == null || tenant.getId() == null) {
            IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
            String tenantId = (String) pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY);
            if (tenantId == null) {
                tenantId = getDefaultTenantPath();
            }
            tenant = new Tenant(tenantId, true);
            return getRoleNameUtils().getPrincipleId(tenant, principal);
        } else {
            return principal;
        }
    } else {
        return principal;
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 9 with Tenant

use of org.pentaho.platform.core.mt.Tenant 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 Tenant

use of org.pentaho.platform.core.mt.Tenant 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

Tenant (org.pentaho.platform.core.mt.Tenant)28 ITenant (org.pentaho.platform.api.mt.ITenant)26 Test (org.junit.Test)10 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)8 ArrayList (java.util.ArrayList)5 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)5 JdbcUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.jdbc.JdbcUserRoleListService)5 List (java.util.List)4 DefaultLdapUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService)4 SearchResultToAttrValueList (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList)4 IOException (java.io.IOException)3 Node (javax.jcr.Node)3 SearchControls (javax.naming.directory.SearchControls)3 Transformer (org.apache.commons.collections.Transformer)3 ChainedTransformer (org.apache.commons.collections.functors.ChainedTransformer)3 Serializable (java.io.Serializable)2 HashSet (java.util.HashSet)2 Properties (java.util.Properties)2 PropertyIterator (javax.jcr.PropertyIterator)2 RepositoryException (javax.jcr.RepositoryException)2