Search in sources :

Example 1 with RepositoryFileSid

use of org.pentaho.platform.api.repository2.unified.RepositoryFileSid 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 2 with RepositoryFileSid

use of org.pentaho.platform.api.repository2.unified.RepositoryFileSid 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 3 with RepositoryFileSid

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

the class ZipExportProcessorTest method init.

@Before
public void init() throws IOException, PlatformInitializationException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException {
    List<Locale> availableLocales = java.util.Collections.singletonList(LOCALE_DEFAULT);
    Properties localePropertries = new Properties();
    localePropertries.setProperty("name1", "value1");
    final RepositoryFile file0 = new RepositoryFile.Builder("").path("/").id("/").folder(true).build();
    final RepositoryFile file1 = new RepositoryFile.Builder("home").path("/home/").id("/home/").folder(true).build();
    final RepositoryFile file2 = new RepositoryFile.Builder("test user").path("/home/test user/").id("/home/test user/").folder(true).build();
    final RepositoryFile file3 = new RepositoryFile.Builder("two words").path("/home/test user/two words/").id("/home/test user/two words/").folder(true).build();
    final RepositoryFile fileX = new RepositoryFile.Builder("eval (+)%.prpt").path("/home/test user/two words/eval (+)%.prpt").id("/home/test user/two words/eval (+)%.prpt").folder(false).build();
    final RepositoryFile[] repoFiles = new RepositoryFile[] { file0, file1, file2, file3, fileX };
    final Map<Serializable, RepositoryFile> repoFilesMap = new HashMap<Serializable, RepositoryFile>();
    for (RepositoryFile f : repoFiles) {
        repoFilesMap.put(f.getId(), f);
    }
    repo = mock(IUnifiedRepository.class);
    final Answer<RepositoryFile> answerRepoGetFile = new Answer<RepositoryFile>() {

        @Override
        public RepositoryFile answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            final Object fileId = args[0];
            return getRepoFile(repoFilesMap, fileId);
        }
    };
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString());
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString(), Mockito.anyBoolean());
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString(), Mockito.anyBoolean(), any(IPentahoLocale.class));
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString(), any(IPentahoLocale.class));
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class));
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class), Mockito.anyBoolean());
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class), Mockito.anyBoolean(), any(IPentahoLocale.class));
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class), any(IPentahoLocale.class));
    Answer<List<RepositoryFile>> answerRepoGetChildren = new Answer<List<RepositoryFile>>() {

        @Override
        public List<RepositoryFile> answer(InvocationOnMock invocation) throws Throwable {
            // returns the following item from <repoFiles>
            RepositoryRequest r = (RepositoryRequest) invocation.getArguments()[0];
            String path = r.getPath();
            RepositoryFile thisFile = getRepoFile(repoFilesMap, path);
            if (thisFile == null || !thisFile.isFolder()) {
                return Collections.emptyList();
            }
            for (int i = 0, n = repoFiles.length - 1; i < n; i++) {
                RepositoryFile iFile = repoFiles[i];
                if (iFile == thisFile || iFile.getId().equals(thisFile.getId())) {
                    return Collections.singletonList(repoFiles[i + 1]);
                }
            }
            return Collections.emptyList();
        }
    };
    Mockito.doAnswer(answerRepoGetChildren).when(repo).getChildren(any(RepositoryRequest.class));
    doReturn(availableLocales).when(repo).getAvailableLocalesForFile(Mockito.any(RepositoryFile.class));
    doReturn(availableLocales).when(repo).getAvailableLocalesForFileById(Mockito.any(Serializable.class));
    doReturn(availableLocales).when(repo).getAvailableLocalesForFileByPath(Mockito.any(String.class));
    doReturn(localePropertries).when(repo).getLocalePropertiesForFileById(Mockito.any(File.class), Mockito.anyString());
    RepositoryFileSid sid = mock(RepositoryFileSid.class);
    doReturn("testUser").when(sid).getName();
    doReturn(Type.USER).when(sid).getType();
    final RepositoryFileAcl mockAcl = mock(RepositoryFileAcl.class);
    doReturn(sid).when(mockAcl).getOwner();
    doReturn(mockAcl).when(repo).getAcl(any(Serializable.class));
    Answer<IRepositoryFileData> answerGetDataForRead = new Answer<IRepositoryFileData>() {

        @Override
        public IRepositoryFileData answer(InvocationOnMock invocation) throws Throwable {
            Serializable id = (Serializable) invocation.getArguments()[0];
            RepositoryFile file = getRepoFile(repoFilesMap, id);
            if (!file.isFolder()) {
                return new SimpleRepositoryFileData(new ByteArrayInputStream(new byte[0]), "UTF-8", MIME_PRPT.getName());
            }
            return null;
        }
    };
    doAnswer(answerGetDataForRead).when(repo).getDataForRead(Mockito.any(Serializable.class), Mockito.any(Class.class));
    exportHandler = new DefaultExportHandler();
    defaultConverter = new StreamConverter(repo);
    PentahoSystem.clearObjectFactory();
    microPlatform = new MicroPlatform(getSolutionPath());
    microPlatform.defineInstance(IUnifiedRepository.class, repo);
    // microPlatform.defineInstance( IPlatformMimeResolver.class, mimeResolver );
    microPlatform.defineInstance(ISolutionEngine.class, Mockito.mock(SolutionEngine.class));
    microPlatform.defineInstance(IDatasourceMgmtService.class, Mockito.mock(IDatasourceMgmtService.class));
    microPlatform.start();
    exportSession = new StandaloneSession();
    PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
    PentahoSessionHolder.setSession(exportSession);
}
Also used : Locale(java.util.Locale) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) Serializable(java.io.Serializable) HashMap(java.util.HashMap) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) List(java.util.List) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) SolutionEngine(org.pentaho.platform.engine.services.solution.SolutionEngine) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Before(org.junit.Before)

Example 4 with RepositoryFileSid

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

the class ExportManifestTest method createMockAce.

private RepositoryFileAce createMockAce(String recipientName, String recipientType, RepositoryFilePermission first, RepositoryFilePermission... rest) {
    RepositoryFileSid.Type type = RepositoryFileSid.Type.valueOf(recipientType);
    RepositoryFileSid recipient = new RepositoryFileSid(recipientName, type);
    return new RepositoryFileAce(recipient, EnumSet.of(first, rest));
}
Also used : RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce)

Example 5 with RepositoryFileSid

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

the class JcrAclNodeHelper method getAclFor.

/**
 * {@inheritDoc}
 */
@Override
public RepositoryFileAcl getAclFor(final RepositoryFile repositoryFile) {
    if (repositoryFile == null) {
        return null;
    }
    // Obtain a reference to ACL node as "system", guaranteed access
    final RepositoryFile aclNode = getAclNode(repositoryFile);
    // Removed redundant call to getAclNode via BISERVER-12780
    if (aclNode == null) {
        return null;
    }
    RepositoryFileAcl acl;
    try {
        acl = unifiedRepository.getAcl(aclNode.getId());
    } catch (Exception e) {
        return null;
    }
    RepositoryFileAcl.Builder aclBuilder = new RepositoryFileAcl.Builder(acl.getId(), acl.getOwner().getName(), RepositoryFileSid.Type.ROLE);
    aclBuilder.aces(acl.getAces());
    // add the Administrator role
    if (canAdminister()) {
        String adminRoleName = PentahoSystem.get(String.class, "singleTenantAdminAuthorityName", PentahoSessionHolder.getSession());
        RepositoryFileAce adminGroup = new RepositoryFileAce(new RepositoryFileSid(adminRoleName, RepositoryFileSid.Type.ROLE), RepositoryFilePermission.ALL);
        aclBuilder.ace(adminGroup);
    }
    return aclBuilder.build();
}
Also used : RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Aggregations

RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)37 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)30 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)25 ITenant (org.pentaho.platform.api.mt.ITenant)15 Test (org.junit.Test)12 RepositoryFileAce (org.pentaho.platform.api.repository2.unified.RepositoryFileAce)10 Builder (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder)7 Matchers.anyString (org.mockito.Matchers.anyString)5 ArrayList (java.util.ArrayList)4 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)4 Serializable (java.io.Serializable)3 Node (javax.jcr.Node)3 RepositoryException (javax.jcr.RepositoryException)3 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)3 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)3 SpringSecurityRolePrincipal (org.pentaho.platform.repository2.unified.jcr.jackrabbit.security.SpringSecurityRolePrincipal)3 Authentication (org.springframework.security.core.Authentication)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)3