Search in sources :

Example 21 with RepositoryFileAclDto

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

the class FileResourceTest method testSetFileAclsError.

@Test
public void testSetFileAclsError() throws Exception {
    RepositoryFileAclDto mockRepositoryFileAclDto = mock(RepositoryFileAclDto.class);
    Messages mockMessages = mock(Messages.class);
    doReturn(mockMessages).when(fileResource).getMessagesInstance();
    Response mockInternalServerErrorResponse = mock(Response.class);
    doReturn(mockInternalServerErrorResponse).when(fileResource).buildStatusResponse(Response.Status.INTERNAL_SERVER_ERROR);
    Exception mockRuntimeException = mock(RuntimeException.class);
    doThrow(mockRuntimeException).when(fileResource.fileService).setFileAcls(PATH_ID, mockRepositoryFileAclDto);
    Response testResponse = fileResource.setFileAcls(PATH_ID, mockRepositoryFileAclDto);
    assertEquals(mockInternalServerErrorResponse, testResponse);
    verify(fileResource, times(1)).getMessagesInstance();
    verify(fileResource, times(1)).buildStatusResponse(Response.Status.INTERNAL_SERVER_ERROR);
    verify(fileResource.fileService, times(1)).setFileAcls(PATH_ID, mockRepositoryFileAclDto);
}
Also used : Response(javax.ws.rs.core.Response) Messages(org.pentaho.platform.web.http.messages.Messages) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) 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) WebApplicationException(javax.ws.rs.WebApplicationException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 22 with RepositoryFileAclDto

use of org.pentaho.platform.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.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 23 with RepositoryFileAclDto

use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto 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)

Example 24 with RepositoryFileAclDto

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

the class DataSourceWizardResourceTest method doGetAnalysisAcl.

@Test
public void doGetAnalysisAcl() throws Exception {
    String domainId = "domainId";
    doReturn(new RepositoryFileAclDto()).when(dataSourceWizardResource.service).getDSWAcl(domainId);
    // no exception thrown
    dataSourceWizardResource.doGetDSWAcl(domainId);
    // 
    doThrow(new PentahoAccessControlException()).when(dataSourceWizardResource.service).getDSWAcl(domainId);
    try {
        dataSourceWizardResource.doGetDSWAcl(domainId);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), e.getResponse().getStatus());
    }
    // 
    doThrow(new FileNotFoundException()).when(dataSourceWizardResource.service).getDSWAcl(domainId);
    try {
        dataSourceWizardResource.doGetDSWAcl(domainId);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.CONFLICT.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) FileNotFoundException(java.io.FileNotFoundException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Example 25 with RepositoryFileAclDto

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

the class MetadataResourceTest method doGetMetadataAcl.

@Test
public void doGetMetadataAcl() throws Exception {
    String domainId = "domainId";
    doReturn(new HashMap<String, InputStream>() {

        {
            put("test", null);
        }
    }).when(metadataResource).getDomainFilesData(domainId);
    doReturn(new RepositoryFileAclDto()).when(metadataResource.service).getMetadataAcl(domainId);
    // no exception thrown
    metadataResource.doGetMetadataAcl(domainId);
    // 
    doThrow(new PentahoAccessControlException()).when(metadataResource.service).getMetadataAcl(domainId);
    try {
        metadataResource.doGetMetadataAcl(domainId);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), e.getResponse().getStatus());
    }
    // 
    doThrow(new FileNotFoundException()).when(metadataResource.service).getMetadataAcl(domainId);
    try {
        metadataResource.doGetMetadataAcl(domainId);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.CONFLICT.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) InputStream(java.io.InputStream) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) FileNotFoundException(java.io.FileNotFoundException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Aggregations

RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)31 Test (org.junit.Test)28 Matchers.anyString (org.mockito.Matchers.anyString)16 InputStream (java.io.InputStream)12 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)9 FileInputStream (java.io.FileInputStream)8 RepositoryFileAclAdapter (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter)8 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)8 RepositoryFileAclAceDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto)7 FileNotFoundException (java.io.FileNotFoundException)6 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 GeneralSecurityException (java.security.GeneralSecurityException)5 ArrayList (java.util.ArrayList)5 StringInputStream (org.apache.tools.ant.filters.StringInputStream)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 WebResource (com.sun.jersey.api.client.WebResource)4 FormDataBodyPart (com.sun.jersey.multipart.FormDataBodyPart)4 JerseyTest (com.sun.jersey.test.framework.JerseyTest)4 Response (javax.ws.rs.core.Response)4