Search in sources :

Example 6 with RepositoryFileAcl

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

the class RepositoryFileImportFileHandler method createFolderJustInTime.

public RepositoryFile createFolderJustInTime(String folderPath, String manifestKey) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
    // The file doesn't exist and it is a folder. Create folder.
    getLogger().trace("Creating implied folder [" + folderPath + "]");
    final Serializable parentId = getParentId(folderPath);
    Assert.notNull(parentId);
    boolean isHidden;
    if (getImportSession().isFileHidden(manifestKey) == null) {
        isHidden = false;
    } else {
        isHidden = getImportSession().isFileHidden(manifestKey);
    }
    RepositoryFile.Builder builder = new RepositoryFile.Builder(RepositoryFilenameUtils.getName(folderPath)).path(RepositoryFilenameUtils.getPath(folderPath)).folder(true).hidden(isHidden);
    RepositoryFile repoFile = builder.build();
    RepositoryFileAcl repoAcl = getImportSession().processAclForFile(manifestKey);
    if (repoAcl != null) {
        repoFile = repository.createFolder(parentId, repoFile, repoAcl, null);
        RepositoryFileAcl repositoryFileAcl = null;
        try {
            repositoryFileAcl = getImportSession().getManifest().getExportManifestEntity(manifestKey).getRepositoryFileAcl();
        } catch (NullPointerException e) {
        // If npe then manifest entry is not defined which is likely so just ignore
        } catch (ExportManifestFormatException e) {
        // Same goes here
        }
        updateAcl(true, repoFile, repositoryFileAcl);
    } else {
        repoFile = repository.createFolder(parentId, repoFile, null);
    }
    getImportSession().getFoldersCreatedImplicitly().add(folderPath);
    return repoFile;
}
Also used : Serializable(java.io.Serializable) ExportManifestFormatException(org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifestFormatException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 7 with RepositoryFileAcl

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

the class RepositoryFileImportFileHandler method updateAcl.

/**
 * Create a formal <code>RepositoryFileAcl</code> object for import.
 *
 * @param newFile
 *          Whether the file is being newly created or was pre-existing
 * @param repositoryFileAcl
 *          The effect Acl as defined in the manifest)
 * @param repositoryFile
 *          The <code>RepositoryFile</code> of the target file
 */
private void updateAcl(boolean newFile, RepositoryFile repositoryFile, RepositoryFileAcl repositoryFileAcl) {
    getLogger().debug("File " + (newFile ? "is new" : "already exists"));
    if (repositoryFileAcl != null && (getImportSession().isApplyAclSettings() || !getImportSession().isRetainOwnership())) {
        RepositoryFileAcl manifestAcl = repositoryFileAcl;
        RepositoryFileAcl originalAcl = repository.getAcl(repositoryFile.getId());
        // Determine who will own this file
        RepositoryFileSid newOwner;
        if (getImportSession().isRetainOwnership()) {
            if (newFile) {
                getLogger().debug("Getting Owner from Session");
                newOwner = getDefaultAcl(repositoryFile).getOwner();
            } else {
                getLogger().debug("Getting Owner from existing file");
                newOwner = originalAcl.getOwner();
            }
        } else {
            getLogger().debug("Getting Owner from Manifest");
            newOwner = manifestAcl.getOwner();
        }
        // Determine the Aces we will use for this file
        // The ACL we will use the permissions from
        RepositoryFileAcl useAclForPermissions;
        if (getImportSession().isApplyAclSettings() && (getImportSession().isOverwriteAclSettings() || newFile)) {
            getLogger().debug("Getting permissions from Manifest");
            useAclForPermissions = manifestAcl;
        } else {
            if (newFile) {
                getLogger().debug("Getting permissions from Default settings");
                useAclForPermissions = getDefaultAcl(repositoryFile);
            } else {
                getLogger().debug("Getting permissions from existing file");
                useAclForPermissions = originalAcl;
            }
        }
        // Make the new Acl if it has changed from the orignal
        if (!newOwner.equals(originalAcl.getOwner()) || !useAclForPermissions.equals(originalAcl)) {
            RepositoryFileAcl updatedAcl = new RepositoryFileAcl(repositoryFile.getId(), newOwner, useAclForPermissions.isEntriesInheriting(), useAclForPermissions.getAces());
            repository.updateAcl(updatedAcl);
        }
    }
}
Also used : RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 8 with RepositoryFileAcl

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

the class RepositoryFileImportFileHandler method createFile.

/**
 * Creates a new file in the repository
 *
 * @param bundle
 * @param data
 */
protected RepositoryFile createFile(final RepositoryFileImportBundle bundle, final String repositoryPath, final IRepositoryFileData data) throws PlatformImportException {
    if (solutionHelper.isInApprovedExtensionList(repositoryPath)) {
        final RepositoryFile file = new RepositoryFile.Builder(bundle.getName()).hidden(isHiddenBundle(bundle)).schedulable(bundle.isSchedulable()).title(RepositoryFile.DEFAULT_LOCALE, getTitle(bundle.getTitle() != null ? bundle.getTitle() : bundle.getName())).versioned(true).build();
        final Serializable parentId = checkAndCreatePath(repositoryPath, getImportSession().getCurrentManifestKey());
        final RepositoryFileAcl acl = bundle.getAcl();
        if (null == acl) {
            return repository.createFile(parentId, file, data, bundle.getComment());
        } else {
            return repository.createFile(parentId, file, data, acl, bundle.getComment());
        }
    } else {
        getLogger().trace("The file [" + repositoryPath + "] is not in the list of approved file extension that can be stored in the repository.");
        return null;
    }
}
Also used : Serializable(java.io.Serializable) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 9 with RepositoryFileAcl

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

the class InheritDefaultAclHandlerTest method testCreateDefaultAcl.

@Test
public void testCreateDefaultAcl() {
    RepositoryFileAcl repositoryFileAcl = inheritDefaultAclHandler.createDefaultAcl(repositoryFile);
    assertTrue(repositoryFileAcl.isEntriesInheriting());
}
Also used : RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 10 with RepositoryFileAcl

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

the class MockUnifiedRepository method createFolder.

@Override
public RepositoryFile createFolder(final Serializable parentFolderId, final RepositoryFile file, final RepositoryFileAcl acl, final String versionMessage) {
    Validate.isTrue(file.isFolder());
    Validate.isTrue(!file.isVersioned());
    if (!hasAccess(parentFolderId, EnumSet.of(WRITE))) {
        throw new AccessDeniedException("access denied");
    }
    FileRecord parentFolder = idManager.getFileById(parentFolderId);
    RepositoryFile fileFromRepo = new RepositoryFile.Builder(file).path(parentFolder.getPath() + (parentFolder.getPath().endsWith(RepositoryFile.SEPARATOR) ? "" : RepositoryFile.SEPARATOR) + file.getName()).title(findTitle(file)).description(findDesc(file)).build();
    RepositoryFileAcl aclFromRepo = new RepositoryFileAcl.Builder(acl).build();
    FileRecord fileRecord = new FileRecord(fileFromRepo, null, aclFromRepo, new HashMap<String, Serializable>());
    idManager.register(fileRecord);
    parentFolder.addChild(fileRecord);
    return fileRecord.getFile();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Serializable(java.io.Serializable) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

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