Search in sources :

Example 1 with RepositoryFileAcl

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-kettle by pentaho.

the class UnifiedRepositoryConnectionAclService method getAcl.

@Override
public ObjectAcl getAcl(ObjectId fileId, boolean forceParentInheriting) throws KettleException {
    RepositoryFileAcl acl = null;
    try {
        acl = pur.getAcl(fileId.getId());
    } catch (Exception drfe) {
        // The user does not have rights to view the acl information.
        throw new KettleException(drfe);
    }
    RepositoryFileSid sid = acl.getOwner();
    ObjectRecipient owner = new RepositoryObjectRecipient(sid.getName());
    if (sid.getType().equals(RepositoryFileSid.Type.USER)) {
        owner.setType(Type.USER);
    } else {
        owner.setType(Type.ROLE);
    }
    ObjectAcl objectAcl = new RepositoryObjectAcl(owner);
    List<RepositoryFileAce> aces;
    if (forceParentInheriting) {
        objectAcl.setEntriesInheriting(true);
        aces = pur.getEffectiveAces(acl.getId(), true);
    } else {
        objectAcl.setEntriesInheriting(acl.isEntriesInheriting());
        aces = (acl.isEntriesInheriting()) ? pur.getEffectiveAces(acl.getId()) : acl.getAces();
    }
    List<ObjectAce> objectAces = new ArrayList<ObjectAce>();
    for (RepositoryFileAce ace : aces) {
        EnumSet<RepositoryFilePermission> permissions = ace.getPermissions();
        EnumSet<RepositoryFilePermission> permissionSet = EnumSet.noneOf(RepositoryFilePermission.class);
        RepositoryFileSid aceSid = ace.getSid();
        ObjectRecipient recipient = new RepositoryObjectRecipient(aceSid.getName());
        if (aceSid.getType().equals(RepositoryFileSid.Type.USER)) {
            recipient.setType(Type.USER);
        } else {
            recipient.setType(Type.ROLE);
        }
        permissionSet.addAll(permissions);
        objectAces.add(new RepositoryObjectAce(recipient, permissionSet));
    }
    objectAcl.setAces(objectAces);
    return objectAcl;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) ObjectAcl(org.pentaho.di.repository.pur.model.ObjectAcl) RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce) ObjectRecipient(org.pentaho.di.repository.ObjectRecipient) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) ArrayList(java.util.ArrayList) ObjectAce(org.pentaho.di.repository.pur.model.ObjectAce) RepositoryObjectAce(org.pentaho.di.repository.pur.model.RepositoryObjectAce) RepositoryObjectAce(org.pentaho.di.repository.pur.model.RepositoryObjectAce) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 2 with RepositoryFileAcl

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-kettle by pentaho.

the class UnifiedRepositoryConnectionAclService method setAcl.

@Override
public void setAcl(ObjectId fileId, ObjectAcl objectAcl) throws KettleException {
    try {
        RepositoryFileAcl acl = pur.getAcl(fileId.getId());
        RepositoryFileAcl.Builder newAclBuilder = new RepositoryFileAcl.Builder(acl).entriesInheriting(objectAcl.isEntriesInheriting()).clearAces();
        if (!objectAcl.isEntriesInheriting()) {
            List<ObjectAce> aces = objectAcl.getAces();
            for (ObjectAce objectAce : aces) {
                EnumSet<RepositoryFilePermission> permissions = objectAce.getPermissions();
                EnumSet<RepositoryFilePermission> permissionSet = EnumSet.noneOf(RepositoryFilePermission.class);
                ObjectRecipient recipient = objectAce.getRecipient();
                RepositoryFileSid sid;
                if (recipient.getType().equals(Type.ROLE)) {
                    sid = new RepositoryFileSid(recipient.getName(), RepositoryFileSid.Type.ROLE);
                } else {
                    sid = new RepositoryFileSid(recipient.getName());
                }
                if (permissions != null) {
                    permissionSet.addAll(permissions);
                }
                newAclBuilder.ace(sid, permissionSet);
            }
        }
        pur.updateAcl(newAclBuilder.build());
    } catch (Exception drfe) {
        // The user does not have rights to view or set the acl information.
        throw new KettleException(drfe);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) ObjectRecipient(org.pentaho.di.repository.ObjectRecipient) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) ObjectAce(org.pentaho.di.repository.pur.model.ObjectAce) RepositoryObjectAce(org.pentaho.di.repository.pur.model.RepositoryObjectAce) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) KettleException(org.pentaho.di.core.exception.KettleException)

Example 3 with RepositoryFileAcl

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-kettle by pentaho.

the class PurRepository method getObjectInformation.

@Override
public RepositoryObject getObjectInformation(ObjectId objectId, RepositoryObjectType objectType) throws KettleException {
    try {
        RepositoryFile repositoryFile;
        try {
            repositoryFile = pur.getFileById(objectId.getId());
        } catch (Exception e) {
            // javax.jcr.Session throws exception, if a node with specified ID does not exist
            // see http://jira.pentaho.com/browse/BISERVER-12758
            log.logError("Error when trying to obtain a file by id: " + objectId.getId(), e);
            return null;
        }
        if (repositoryFile == null) {
            return null;
        }
        RepositoryFileAcl repositoryFileAcl = pur.getAcl(repositoryFile.getId());
        String parentPath = getParentPath(repositoryFile.getPath());
        String name = repositoryFile.getTitle();
        String description = repositoryFile.getDescription();
        Date modifiedDate = repositoryFile.getLastModifiedDate();
        // String creatorId = repositoryFile.getCreatorId();
        String ownerName = repositoryFileAcl != null ? repositoryFileAcl.getOwner().getName() : "";
        boolean deleted = isDeleted(repositoryFile);
        RepositoryDirectoryInterface directory = findDirectory(parentPath);
        return new RepositoryObject(objectId, name, directory, ownerName, modifiedDate, objectType, description, deleted);
    } catch (Exception e) {
        throw new KettleException("Unable to get object information for object with id=" + objectId, e);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObject(org.pentaho.di.repository.RepositoryObject) EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException) Date(java.util.Date)

Example 4 with RepositoryFileAcl

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.

the class ExportManifestEntity method getRepositoryFileAcl.

/**
 * Helper method for importing. Returns a FileRepositoryAcl object for the the ExportManifestEntity. Will return null
 * if there is no EntityAcl present.
 *
 * @return RepositoryFile
 */
public RepositoryFileAcl getRepositoryFileAcl() throws ExportManifestFormatException {
    RepositoryFileAcl repositoryFileAcl;
    EntityAcl entityAcl = getEntityAcl();
    if (entityAcl == null) {
        return null;
    }
    ArrayList<RepositoryFileAce> repositoryFileAces = new ArrayList<RepositoryFileAce>();
    RepositoryFileSid rfs;
    for (EntityAcl.Aces ace : entityAcl.getAces()) {
        rfs = getSid(ace.getRecipient(), ace.getRecipientType());
        HashSet<RepositoryFilePermission> permissionSet = new HashSet<RepositoryFilePermission>();
        for (String permission : ace.getPermissions()) {
            permissionSet.add(getPermission(permission));
        }
        RepositoryFileAce repositoryFileAce = new RepositoryFileAce(rfs, EnumSet.copyOf(permissionSet));
        repositoryFileAces.add(repositoryFileAce);
    }
    repositoryFileAcl = new RepositoryFileAcl("", getSid(entityAcl.getOwner(), entityAcl.getOwnerType()), entityAcl.isEntriesInheriting(), repositoryFileAces);
    return repositoryFileAcl;
}
Also used : RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce) ArrayList(java.util.ArrayList) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) EntityAcl(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.EntityAcl) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) HashSet(java.util.HashSet)

Example 5 with RepositoryFileAcl

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.

the class ExportManifestEntity method createEntityAcl.

private void createEntityAcl(RepositoryFileAcl repositoryFileAcl) {
    DefaultTenantedPrincipleNameResolver nameResolver = new DefaultTenantedPrincipleNameResolver();
    if (repositoryFileAcl == null) {
        return;
    }
    entityAcl = new EntityAcl();
    entityAcl.setEntriesInheriting(repositoryFileAcl.isEntriesInheriting());
    entityAcl.setOwner(nameResolver.getPrincipleName(repositoryFileAcl.getOwner().getName()));
    entityAcl.setOwnerType(repositoryFileAcl.getOwner().getType().name());
    List<EntityAcl.Aces> aces = entityAcl.getAces();
    aces.clear();
    for (RepositoryFileAce repositoryFileAce : repositoryFileAcl.getAces()) {
        EntityAcl.Aces ace = new EntityAcl.Aces();
        ace.setRecipient(nameResolver.getPrincipleName(repositoryFileAce.getSid().getName()));
        ace.setRecipientType(repositoryFileAce.getSid().getType().name());
        List<String> permissions = ace.getPermissions();
        for (RepositoryFilePermission permission : repositoryFileAce.getPermissions()) {
            permissions.add(permission.toString());
        }
        aces.add(ace);
    }
}
Also used : RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) DefaultTenantedPrincipleNameResolver(org.pentaho.platform.security.userroledao.DefaultTenantedPrincipleNameResolver) EntityAcl(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.EntityAcl)

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