Search in sources :

Example 91 with RevisionDTO

use of org.apache.nifi.web.api.dto.RevisionDTO 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

RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)91 Response (javax.ws.rs.core.Response)45 Authorizable (org.apache.nifi.authorization.resource.Authorizable)30 PermissionsDTO (org.apache.nifi.web.api.dto.PermissionsDTO)29 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)26 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)26 PortEntity (org.apache.nifi.web.api.entity.PortEntity)25 HashMap (java.util.HashMap)24 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)24 Map (java.util.Map)23 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)23 Set (java.util.Set)22 Collectors (java.util.stream.Collectors)22 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)22 ControllerServiceEntity (org.apache.nifi.web.api.entity.ControllerServiceEntity)22 ScheduledState (org.apache.nifi.controller.ScheduledState)21 ControllerServiceState (org.apache.nifi.controller.service.ControllerServiceState)21 VersionControlInformationDTO (org.apache.nifi.web.api.dto.VersionControlInformationDTO)21 HashSet (java.util.HashSet)20 Authorizer (org.apache.nifi.authorization.Authorizer)19