Search in sources :

Example 66 with ProcessorDTO

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

the class ITAccessTokenEndpoint method createProcessor.

private ProcessorDTO createProcessor(final String token) throws Exception {
    String url = BASE_URL + "/process-groups/root/processors";
    // authorization header
    Map<String, String> headers = new HashMap<>();
    headers.put("Authorization", "Bearer " + token);
    // create the processor
    ProcessorDTO processor = new ProcessorDTO();
    processor.setName("Copy");
    processor.setType(SourceTestProcessor.class.getName());
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(CLIENT_ID);
    revision.setVersion(0l);
    // create the entity body
    ProcessorEntity entity = new ProcessorEntity();
    entity.setRevision(revision);
    entity.setComponent(processor);
    // perform the request
    Response response = TOKEN_USER.testPostWithHeaders(url, entity, headers);
    // ensure the request is successful
    Assert.assertEquals(201, response.getStatus());
    // get the entity body
    entity = response.readEntity(ProcessorEntity.class);
    // verify creation
    processor = entity.getComponent();
    Assert.assertEquals("Copy", processor.getName());
    Assert.assertEquals("org.apache.nifi.integration.util.SourceTestProcessor", processor.getType());
    return processor;
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) SourceTestProcessor(org.apache.nifi.integration.util.SourceTestProcessor) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Example 67 with ProcessorDTO

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

the class ITProcessorAccessControl method testNoneUserPutProcessor.

/**
 * Ensures the NONE user cannot put a processor.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutProcessor() throws Exception {
    final ProcessorEntity entity = getRandomProcessor(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
    final String updatedName = "Updated Name";
    // attempt to update the name
    final ProcessorDTO requestDto = new ProcessorDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);
    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID);
    final ProcessorEntity requestEntity = new ProcessorEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);
    // perform the request
    final Response response = updateProcessor(helper.getNoneUser(), requestEntity);
    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Test(org.junit.Test)

Example 68 with ProcessorDTO

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

the class ITProcessorAccessControl method testCreateRestrictedProcessor.

/**
 * Tests attempt to create a restricted processor.
 *
 * @throws Exception if there is an error creating this processor
 */
@Test
public void testCreateRestrictedProcessor() throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/processors";
    // create the processor
    ProcessorDTO processor = new ProcessorDTO();
    processor.setName("restricted");
    processor.setType(RestrictedProcessor.class.getName());
    // 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 but no restricted access
    Response response = helper.getReadWriteUser().testPost(url, entity);
    // ensure the request is successful
    assertEquals(403, response.getStatus());
    // perform the request as a user with read/write and only execute code restricted access
    response = helper.getExecuteCodeUser().testPost(url, entity);
    // ensure the request is successful
    assertEquals(403, response.getStatus());
    // perform the request as a user with read/write and restricted access
    response = helper.getPrivilegedUser().testPost(url, entity);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    final ProcessorEntity responseEntity = response.readEntity(ProcessorEntity.class);
    // remove the restricted component
    deleteRestrictedComponent(responseEntity, helper.getPrivilegedUser());
}
Also used : Response(javax.ws.rs.core.Response) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ExecuteCodeRestrictedProcessor(org.apache.nifi.integration.util.ExecuteCodeRestrictedProcessor) RestrictedProcessor(org.apache.nifi.integration.util.RestrictedProcessor) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Test(org.junit.Test)

Example 69 with ProcessorDTO

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

ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)69 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)24 ArrayList (java.util.ArrayList)21 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)19 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)19 HashMap (java.util.HashMap)17 HashSet (java.util.HashSet)16 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)15 PortDTO (org.apache.nifi.web.api.dto.PortDTO)15 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)15 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)13 Map (java.util.Map)11 Response (javax.ws.rs.core.Response)11 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)11 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)11 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)10 List (java.util.List)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)9 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)9