Search in sources :

Example 6 with RepositoryFileAclAceDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto 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.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) WebResource(com.sun.jersey.api.client.WebResource) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Example 7 with RepositoryFileAclAceDto

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

the class DataSourcePublishIT method generateACL.

private RepositoryFileAclDto generateACL(String userOrRole, RepositoryFileSid.Type type) {
    final RepositoryFileAclDto aclDto = new RepositoryFileAclDto();
    aclDto.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
    aclDto.setOwner(singleTenantAdminUserName);
    aclDto.setEntriesInheriting(false);
    final ArrayList<RepositoryFileAclAceDto> aces = new ArrayList<RepositoryFileAclAceDto>();
    final RepositoryFileAclAceDto aceDto = new RepositoryFileAclAceDto();
    aceDto.setRecipient(userOrRole);
    aceDto.setRecipientType(type.ordinal());
    final ArrayList<Integer> permissions = new ArrayList<Integer>();
    permissions.add(RepositoryFilePermission.ALL.ordinal());
    aceDto.setPermissions(permissions);
    aces.add(aceDto);
    aclDto.setAces(aces);
    return aclDto;
}
Also used : RepositoryFileAclAceDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) ArrayList(java.util.ArrayList)

Aggregations

RepositoryFileAclAceDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto)7 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)5 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)4 Serializable (java.io.Serializable)2 GeneralSecurityException (java.security.GeneralSecurityException)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)2 StringKeyStringValueDto (org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 JerseyTest (com.sun.jersey.test.framework.JerseyTest)1 FileNotFoundException (java.io.FileNotFoundException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Matchers.anyString (org.mockito.Matchers.anyString)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1