Search in sources :

Example 46 with RepositoryFileAclDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.

the class MetadataServiceTest method testGetMetadataDatasourceAclNoDS.

@Test(expected = FileNotFoundException.class)
public void testGetMetadataDatasourceAclNoDS() throws Exception {
    String domainId = DOMAIN_ID;
    doReturn(true).when(metadataService).canManageACL();
    when(metadataService.aclAwarePentahoMetadataDomainRepositoryImporter.getAclFor(domainId)).thenReturn(null);
    final RepositoryFileAclDto aclDto = metadataService.getMetadataAcl(domainId);
    verify(metadataService.aclAwarePentahoMetadataDomainRepositoryImporter).getAclFor(eq(domainId));
    assertNull(aclDto);
}
Also used : RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 47 with RepositoryFileAclDto

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

the class FileResourceIT method testFileAcls.

@Test
public void testFileAcls() throws InterruptedException {
    loginAsRepositoryAdmin();
    ITenant systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminAuthorityName });
    ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(mainTenant_1, "admin", "password", "", new String[] { adminAuthorityName });
    try {
        login("admin", mainTenant_1, new String[] { authenticatedAuthorityName });
        mp.defineInstance(IUnifiedRepository.class, repo);
        String publicFolderPath = ClientRepositoryPaths.getPublicFolderPath();
        createTestFile(publicFolderPath.replaceAll("/", ":") + ":" + "aclFile.txt", "abcdefg");
        WebResource webResource = resource();
        RepositoryFileAclDto fileAcls = webResource.path("repo/files/public:aclFile.txt/acl").accept(APPLICATION_XML).get(RepositoryFileAclDto.class);
        List<RepositoryFileAclAceDto> aces = fileAcls.getAces();
        assertEquals(2, aces.size());
        RepositoryFileAclAceDto ace = aces.get(0);
        assertEquals(authenticatedAuthorityName, ace.getRecipient());
        List<Integer> permissions = ace.getPermissions();
        assertEquals(1, permissions.size());
        Assert.assertTrue(permissions.contains(new Integer(0)));
        String authenticated = authenticatedAuthorityName;
        aces = new ArrayList<RepositoryFileAclAceDto>();
        ace = new RepositoryFileAclAceDto();
        ace.setRecipient(authenticated);
        ace.setRecipientType(1);
        permissions = new ArrayList<Integer>();
        permissions.add(2);
        ace.setPermissions(permissions);
        aces.add(ace);
        fileAcls.setAces(aces);
        ClientResponse putResponse2 = webResource.path("repo/files/public:aclFile.txt/acl").type(APPLICATION_XML).put(ClientResponse.class, fileAcls);
        assertResponse(putResponse2, Status.OK);
    } catch (Throwable ex) {
        TestCase.fail();
    } finally {
        cleanupUserAndRoles(mainTenant_1);
        cleanupUserAndRoles(systemTenant);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ITenant(org.pentaho.platform.api.mt.ITenant) RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) WebResource(com.sun.jersey.api.client.WebResource) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Example 48 with RepositoryFileAclDto

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

the class FileService method doSetMetadata.

/**
 * Set the metadata on a file
 *
 * @param pathId
 * @param metadata
 * @throws GeneralSecurityException
 */
public void doSetMetadata(String pathId, List<StringKeyStringValueDto> metadata) throws GeneralSecurityException {
    RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
    RepositoryFileAclDto fileAcl = getRepoWs().getAcl(file.getId());
    boolean canManage = getSession().getName().equals(fileAcl.getOwner()) || (getPolicy().isAllowed(RepositoryReadAction.NAME) && getPolicy().isAllowed(RepositoryCreateAction.NAME) && getPolicy().isAllowed(AdministerSecurityAction.NAME));
    if (!canManage) {
        if (fileAcl.isEntriesInheriting()) {
            List<RepositoryFileAclAceDto> aces = getRepoWs().getEffectiveAces(file.getId());
            fileAcl.setAces(aces, fileAcl.isEntriesInheriting());
        }
        for (int i = 0; i < fileAcl.getAces().size(); i++) {
            RepositoryFileAclAceDto acl = fileAcl.getAces().get(i);
            if (acl.getRecipient().equals(getSession().getName())) {
                if (acl.getPermissions().contains(RepositoryFilePermission.ACL_MANAGEMENT.ordinal()) || acl.getPermissions().contains(RepositoryFilePermission.ALL.ordinal())) {
                    canManage = true;
                    break;
                }
            }
        }
    }
    if (canManage) {
        Map<String, Serializable> fileMetadata = getRepository().getFileMetadata(file.getId());
        boolean isHidden = RepositoryFile.HIDDEN_BY_DEFAULT;
        boolean isSchedulable = RepositoryFile.SCHEDULABLE_BY_DEFAULT;
        fileMetadata.remove(RepositoryFile.HIDDEN_KEY);
        for (StringKeyStringValueDto nv : metadata) {
            // don't add hidden to the list because it is not actually part of the metadata node
            String key = nv.getKey();
            if (RepositoryFile.HIDDEN_KEY.equalsIgnoreCase(key)) {
                isHidden = BooleanUtils.toBoolean(nv.getValue());
                continue;
            }
            if (RepositoryFile.SCHEDULABLE_KEY.equalsIgnoreCase(key)) {
                isSchedulable = BooleanUtils.toBoolean(nv.getValue());
            }
            fileMetadata.put(key, nv.getValue());
        }
        // now update the rest of the metadata
        if (!file.isFolder()) {
            getRepository().setFileMetadata(file.getId(), fileMetadata);
        }
        // handle hidden flag if it is different
        if (file.isHidden() != isHidden) {
            file.setHidden(isHidden);
            file.setNotSchedulable(!isSchedulable);
            /*
         * Since we cannot simply set the new value, use the RepositoryFileAdapter to create a new instance and then
         * update the original.
         */
            RepositoryFile sourceFile = getRepository().getFileById(file.getId());
            RepositoryFileDto destFileDto = toFileDto(sourceFile, null, false);
            destFileDto.setHidden(isHidden);
            destFileDto.setNotSchedulable(!isSchedulable);
            RepositoryFile destFile = toFile(destFileDto);
            // add the existing acls and file data
            RepositoryFileAcl acl = getRepository().getAcl(sourceFile.getId());
            if (!file.isFolder()) {
                IRepositoryFileData data = RepositoryFileHelper.getFileData(sourceFile);
                getRepository().updateFile(destFile, data, null);
                getRepository().updateAcl(acl);
            } else {
                getRepository().updateFolder(destFile, null);
            }
        }
    } else {
        throw new GeneralSecurityException();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) Serializable(java.io.Serializable) RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) GeneralSecurityException(java.security.GeneralSecurityException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 49 with RepositoryFileAclDto

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

the class FileService method addAdminRole.

protected void addAdminRole(RepositoryFileAclDto fileAcl) {
    String adminRoleName = PentahoSystem.get(String.class, "singleTenantAdminAuthorityName", PentahoSessionHolder.getSession());
    if (fileAcl.getAces() == null) {
        fileAcl.setAces(new LinkedList<RepositoryFileAclAceDto>());
    }
    for (RepositoryFileAclAceDto facl : fileAcl.getAces()) {
        if (facl.getRecipient().equals(adminRoleName) && facl.getRecipientType() == 1) {
            return;
        }
    }
    RepositoryFileAclAceDto adminGroup = new RepositoryFileAclAceDto();
    adminGroup.setRecipient(adminRoleName);
    adminGroup.setRecipientType(1);
    adminGroup.setModifiable(false);
    List<Integer> perms = new LinkedList<Integer>();
    perms.add(4);
    adminGroup.setPermissions(perms);
    fileAcl.getAces().add(adminGroup);
}
Also used : RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) LinkedList(java.util.LinkedList)

Example 50 with RepositoryFileAclDto

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

the class FileService method doSetContentCreator.

/**
 * Store content creator of the selected repository file
 *
 * @param pathId colon separated path for the repository file
 * <pre function="syntax.xml">
 *    :path:to:file:id
 * </pre>
 * @param contentCreator repository file
 * <pre function="syntax.xml">
 *   <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 *     &lt;repositoryFileDto&gt;
 *     &lt;createdDate&gt;1402911997019&lt;/createdDate&gt;
 *     &lt;fileSize&gt;3461&lt;/fileSize&gt;
 *     &lt;folder&gt;false&lt;/folder&gt;
 *     &lt;hidden&gt;false&lt;/hidden&gt;
 *     &lt;id&gt;ff11ac89-7eda-4c03-aab1-e27f9048fd38&lt;/id&gt;
 *     &lt;lastModifiedDate&gt;1406647160536&lt;/lastModifiedDate&gt;
 *     &lt;locale&gt;en&lt;/locale&gt;
 *     &lt;localePropertiesMapEntries&gt;
 *       &lt;localeMapDto&gt;
 *         &lt;locale&gt;default&lt;/locale&gt;
 *         &lt;properties&gt;
 *           &lt;stringKeyStringValueDto&gt;
 *             &lt;key&gt;file.title&lt;/key&gt;
 *             &lt;value&gt;myFile&lt;/value&gt;
 *           &lt;/stringKeyStringValueDto&gt;
 *           &lt;stringKeyStringValueDto&gt;
 *             &lt;key&gt;jcr:primaryType&lt;/key&gt;
 *             &lt;value&gt;nt:unstructured&lt;/value&gt;
 *           &lt;/stringKeyStringValueDto&gt;
 *           &lt;stringKeyStringValueDto&gt;
 *             &lt;key&gt;title&lt;/key&gt;
 *             &lt;value&gt;myFile&lt;/value&gt;
 *           &lt;/stringKeyStringValueDto&gt;
 *           &lt;stringKeyStringValueDto&gt;
 *             &lt;key&gt;file.description&lt;/key&gt;
 *             &lt;value&gt;myFile Description&lt;/value&gt;
 *           &lt;/stringKeyStringValueDto&gt;
 *         &lt;/properties&gt;
 *       &lt;/localeMapDto&gt;
 *     &lt;/localePropertiesMapEntries&gt;
 *     &lt;locked&gt;false&lt;/locked&gt;
 *     &lt;name&gt;myFile.prpt&lt;/name&gt;&lt;/name&gt;
 *     &lt;originalParentFolderPath&gt;/public/admin&lt;/originalParentFolderPath&gt;
 *     &lt;ownerType&gt;-1&lt;/ownerType&gt;
 *     &lt;path&gt;/public/admin/ff11ac89-7eda-4c03-aab1-e27f9048fd38&lt;/path&gt;
 *     &lt;title&gt;myFile&lt;/title&gt;
 *     &lt;versionId&gt;1.9&lt;/versionId&gt;
 *     &lt;versioned&gt;true&lt;/versioned&gt;
 *   &lt;/repositoryFileAclDto&gt;
 * </pre>
 * @throws FileNotFoundException
 */
public void doSetContentCreator(String pathId, RepositoryFileDto contentCreator) throws FileNotFoundException {
    RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
    if (file == null) {
        throw new FileNotFoundException();
    }
    try {
        Map<String, Serializable> fileMetadata = getRepository().getFileMetadata(file.getId());
        fileMetadata.put(PentahoJcrConstants.PHO_CONTENTCREATOR, contentCreator.getId());
        getRepository().setFileMetadata(file.getId(), fileMetadata);
    } catch (Exception e) {
        throw new InternalError();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) FileNotFoundException(java.io.FileNotFoundException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExportException(org.pentaho.platform.plugin.services.importexport.ExportException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException)

Aggregations

Test (org.junit.Test)41 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)26 RepositoryFileAclDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto)20 Matchers.anyString (org.mockito.Matchers.anyString)16 InputStream (java.io.InputStream)14 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)13 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)11 RepositoryFileAclAceDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto)11 FileInputStream (java.io.FileInputStream)9 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)9 RepositoryFileDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)9 ArrayList (java.util.ArrayList)8 RepositoryFileAclAdapter (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileNotFoundException (java.io.FileNotFoundException)7 Serializable (java.io.Serializable)7 GeneralSecurityException (java.security.GeneralSecurityException)6 IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4