Search in sources :

Example 6 with SnippetDTO

use of org.apache.nifi.web.api.dto.SnippetDTO in project nifi by apache.

the class ITProcessorAccessControl method createSnippetWithRestrictedComponent.

private Tuple<ProcessorEntity, SnippetEntity> createSnippetWithRestrictedComponent(final String restrictedClassName, final NiFiTestUser user) throws Exception {
    final String processorUrl = helper.getBaseUrl() + "/process-groups/root/processors";
    final String snippetUrl = helper.getBaseUrl() + "/snippets";
    // create the processor
    ProcessorDTO processor = new ProcessorDTO();
    processor.setName("restricted");
    processor.setType(restrictedClassName);
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);
    // create the entity body
    ProcessorEntity entity = new ProcessorEntity();
    entity.setRevision(revision);
    entity.setComponent(processor);
    // perform the request as a user with read/write and restricted access
    Response response = user.testPost(processorUrl, entity);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    // get the response
    final ProcessorEntity responseProcessorEntity = response.readEntity(ProcessorEntity.class);
    // build the snippet for the copy/paste
    final SnippetDTO snippet = new SnippetDTO();
    snippet.setParentGroupId(responseProcessorEntity.getComponent().getParentGroupId());
    snippet.getProcessors().put(responseProcessorEntity.getId(), responseProcessorEntity.getRevision());
    // create the entity body
    final SnippetEntity snippetEntity = new SnippetEntity();
    snippetEntity.setSnippet(snippet);
    // create the snippet
    response = helper.getNoneUser().testPost(snippetUrl, snippetEntity);
    // ensure the request failed... need either read or write to create snippet (not sure what snippet will be used for)
    assertEquals(403, response.getStatus());
    // create the snippet
    response = helper.getReadWriteUser().testPost(snippetUrl, snippetEntity);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    // get the response
    return new Tuple<>(responseProcessorEntity, response.readEntity(SnippetEntity.class));
}
Also used : Response(javax.ws.rs.core.Response) SnippetDTO(org.apache.nifi.web.api.dto.SnippetDTO) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) SnippetEntity(org.apache.nifi.web.api.entity.SnippetEntity) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Tuple(org.apache.nifi.util.Tuple)

Aggregations

SnippetDTO (org.apache.nifi.web.api.dto.SnippetDTO)6 SnippetEntity (org.apache.nifi.web.api.entity.SnippetEntity)4 Response (javax.ws.rs.core.Response)3 AccessDeniedException (org.apache.nifi.authorization.AccessDeniedException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 AuthorizableLookup (org.apache.nifi.authorization.AuthorizableLookup)2 Authorizer (org.apache.nifi.authorization.Authorizer)2 RequestAction (org.apache.nifi.authorization.RequestAction)2 Authorizable (org.apache.nifi.authorization.resource.Authorizable)2 NiFiUserUtils (org.apache.nifi.authorization.user.NiFiUserUtils)2 Snippet (org.apache.nifi.controller.Snippet)2 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)2