Search in sources :

Example 1 with CreateTemplateRequestEntity

use of org.apache.nifi.web.api.entity.CreateTemplateRequestEntity in project nifi by apache.

the class ITProcessorAccessControl method testTemplateWithRestrictedProcessor.

/**
 * Tests attempting to use a template with a restricted processor.
 *
 * @throws Exception ex
 */
@Test
public void testTemplateWithRestrictedProcessor() throws Exception {
    final String createTemplateUrl = helper.getBaseUrl() + "/process-groups/root/templates";
    final String instantiateTemplateUrl = helper.getBaseUrl() + "/process-groups/root/template-instance";
    final Tuple<ProcessorEntity, SnippetEntity> tuple = createSnippetWithRestrictedComponent(RestrictedProcessor.class.getName(), helper.getPrivilegedUser());
    final SnippetEntity snippetEntity = tuple.getValue();
    // create the template
    final CreateTemplateRequestEntity createTemplateRequest = new CreateTemplateRequestEntity();
    createTemplateRequest.setSnippetId(snippetEntity.getSnippet().getId());
    createTemplateRequest.setName("test");
    // create the snippet
    Response response = helper.getWriteUser().testPost(createTemplateUrl, createTemplateRequest);
    // ensure the request failed... need read perms to the components in the snippet
    assertEquals(403, response.getStatus());
    response = helper.getReadWriteUser().testPost(createTemplateUrl, createTemplateRequest);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    final TemplateEntity templateEntity = response.readEntity(TemplateEntity.class);
    // build the template request
    final InstantiateTemplateRequestEntity instantiateTemplateRequest = new InstantiateTemplateRequestEntity();
    instantiateTemplateRequest.setTemplateId(templateEntity.getTemplate().getId());
    instantiateTemplateRequest.setOriginX(0.0);
    instantiateTemplateRequest.setOriginY(0.0);
    // create the snippet
    response = helper.getReadWriteUser().testPost(instantiateTemplateUrl, instantiateTemplateRequest);
    // ensure the request failed... need privileged user since the template is comprised of restricted components
    assertEquals(403, response.getStatus());
    // create the snippet
    response = helper.getExecuteCodeUser().testPost(instantiateTemplateUrl, instantiateTemplateRequest);
    // ensure the request failed... need privileged user since the template is comprised of restricted components
    assertEquals(403, response.getStatus());
    // create the snippet
    response = helper.getPrivilegedUser().testPost(instantiateTemplateUrl, instantiateTemplateRequest);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    final FlowEntity flowEntity = response.readEntity(FlowEntity.class);
    // clean up the resources created during this test
    deleteTemplate(templateEntity);
    deleteRestrictedComponent(tuple.getKey(), helper.getPrivilegedUser());
    deleteRestrictedComponent(flowEntity.getFlow().getProcessors().stream().findFirst().orElse(null), helper.getPrivilegedUser());
}
Also used : Response(javax.ws.rs.core.Response) InstantiateTemplateRequestEntity(org.apache.nifi.web.api.entity.InstantiateTemplateRequestEntity) SnippetEntity(org.apache.nifi.web.api.entity.SnippetEntity) ExecuteCodeRestrictedProcessor(org.apache.nifi.integration.util.ExecuteCodeRestrictedProcessor) RestrictedProcessor(org.apache.nifi.integration.util.RestrictedProcessor) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) CreateTemplateRequestEntity(org.apache.nifi.web.api.entity.CreateTemplateRequestEntity) TemplateEntity(org.apache.nifi.web.api.entity.TemplateEntity) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) FlowEntity(org.apache.nifi.web.api.entity.FlowEntity) Test(org.junit.Test)

Example 2 with CreateTemplateRequestEntity

use of org.apache.nifi.web.api.entity.CreateTemplateRequestEntity in project nifi by apache.

the class ITProcessorAccessControl method templateWithExecuteCodeRestrictedProcessor.

private void templateWithExecuteCodeRestrictedProcessor(final NiFiTestUser user) throws Exception {
    final String createTemplateUrl = helper.getBaseUrl() + "/process-groups/root/templates";
    final String instantiateTemplateUrl = helper.getBaseUrl() + "/process-groups/root/template-instance";
    final Tuple<ProcessorEntity, SnippetEntity> tuple = createSnippetWithRestrictedComponent(ExecuteCodeRestrictedProcessor.class.getName(), helper.getPrivilegedUser());
    final SnippetEntity snippetEntity = tuple.getValue();
    // create the template
    final CreateTemplateRequestEntity createTemplateRequest = new CreateTemplateRequestEntity();
    createTemplateRequest.setSnippetId(snippetEntity.getSnippet().getId());
    createTemplateRequest.setName("test");
    // create the snippet
    Response response = helper.getWriteUser().testPost(createTemplateUrl, createTemplateRequest);
    // ensure the request failed... need read perms to the components in the snippet
    assertEquals(403, response.getStatus());
    response = helper.getReadWriteUser().testPost(createTemplateUrl, createTemplateRequest);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    final TemplateEntity templateEntity = response.readEntity(TemplateEntity.class);
    // build the template request
    final InstantiateTemplateRequestEntity instantiateTemplateRequest = new InstantiateTemplateRequestEntity();
    instantiateTemplateRequest.setTemplateId(templateEntity.getTemplate().getId());
    instantiateTemplateRequest.setOriginX(0.0);
    instantiateTemplateRequest.setOriginY(0.0);
    // create the snippet
    response = helper.getReadWriteUser().testPost(instantiateTemplateUrl, instantiateTemplateRequest);
    // ensure the request failed... need privileged user since the template is comprised of restricted components
    assertEquals(403, response.getStatus());
    // create the snippet
    response = user.testPost(instantiateTemplateUrl, instantiateTemplateRequest);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    final FlowEntity flowEntity = response.readEntity(FlowEntity.class);
    // clean up the resources created during this test
    deleteTemplate(templateEntity);
    deleteRestrictedComponent(tuple.getKey(), user);
    deleteRestrictedComponent(flowEntity.getFlow().getProcessors().stream().findFirst().orElse(null), user);
}
Also used : Response(javax.ws.rs.core.Response) InstantiateTemplateRequestEntity(org.apache.nifi.web.api.entity.InstantiateTemplateRequestEntity) SnippetEntity(org.apache.nifi.web.api.entity.SnippetEntity) ExecuteCodeRestrictedProcessor(org.apache.nifi.integration.util.ExecuteCodeRestrictedProcessor) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) CreateTemplateRequestEntity(org.apache.nifi.web.api.entity.CreateTemplateRequestEntity) TemplateEntity(org.apache.nifi.web.api.entity.TemplateEntity) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) FlowEntity(org.apache.nifi.web.api.entity.FlowEntity)

Aggregations

Response (javax.ws.rs.core.Response)2 ExecuteCodeRestrictedProcessor (org.apache.nifi.integration.util.ExecuteCodeRestrictedProcessor)2 CreateTemplateRequestEntity (org.apache.nifi.web.api.entity.CreateTemplateRequestEntity)2 FlowEntity (org.apache.nifi.web.api.entity.FlowEntity)2 InstantiateTemplateRequestEntity (org.apache.nifi.web.api.entity.InstantiateTemplateRequestEntity)2 ProcessGroupFlowEntity (org.apache.nifi.web.api.entity.ProcessGroupFlowEntity)2 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)2 SnippetEntity (org.apache.nifi.web.api.entity.SnippetEntity)2 TemplateEntity (org.apache.nifi.web.api.entity.TemplateEntity)2 RestrictedProcessor (org.apache.nifi.integration.util.RestrictedProcessor)1 Test (org.junit.Test)1