Search in sources :

Example 56 with ProcessorEntity

use of org.apache.nifi.web.api.entity.ProcessorEntity 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)

Example 57 with ProcessorEntity

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

the class ITProcessorAccessControl method testReadUserPutProcessor.

/**
 * Ensures the READ user cannot put a processor.
 *
 * @throws Exception ex
 */
@Test
public void testReadUserPutProcessor() throws Exception {
    final ProcessorEntity entity = getRandomProcessor(helper.getReadUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
    // attempt update the name
    entity.getRevision().setClientId(READ_CLIENT_ID);
    entity.getComponent().setName("Updated Name");
    // perform the request
    final Response response = updateProcessor(helper.getReadUser(), entity);
    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) Test(org.junit.Test)

Example 58 with ProcessorEntity

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

the class ITProcessorAccessControl method getRandomProcessor.

private ProcessorEntity getRandomProcessor(final NiFiTestUser user) throws Exception {
    final String url = helper.getBaseUrl() + "/flow/process-groups/root";
    // get the processors
    final Response response = user.testGet(url);
    // ensure the response was successful
    assertEquals(200, response.getStatus());
    // unmarshal
    final ProcessGroupFlowEntity flowEntity = response.readEntity(ProcessGroupFlowEntity.class);
    final FlowDTO flowDto = flowEntity.getProcessGroupFlow().getFlow();
    final Set<ProcessorEntity> processors = flowDto.getProcessors();
    // ensure the correct number of processors
    assertFalse(processors.isEmpty());
    // use the first processor as the target
    Iterator<ProcessorEntity> processorIter = processors.iterator();
    assertTrue(processorIter.hasNext());
    return processorIter.next();
}
Also used : Response(javax.ws.rs.core.Response) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity)

Example 59 with ProcessorEntity

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

the class ITProcessorAccessControl method copyPasteExecuteCodeRestrictedProcessor.

private void copyPasteExecuteCodeRestrictedProcessor(final NiFiTestUser user) throws Exception {
    final String copyUrl = helper.getBaseUrl() + "/process-groups/root/snippet-instance";
    final Tuple<ProcessorEntity, SnippetEntity> tuple = createSnippetWithRestrictedComponent(ExecuteCodeRestrictedProcessor.class.getName(), user);
    final SnippetEntity snippetEntity = tuple.getValue();
    // build the copy/paste request
    final CopySnippetRequestEntity copyRequest = new CopySnippetRequestEntity();
    copyRequest.setSnippetId(snippetEntity.getSnippet().getId());
    copyRequest.setOriginX(0.0);
    copyRequest.setOriginY(0.0);
    // create the snippet
    Response response = helper.getReadWriteUser().testPost(copyUrl, copyRequest);
    // ensure the request failed... need privileged users since snippet comprised of the restricted components
    assertEquals(403, response.getStatus());
    // perform the request as a user with read/write and only execute code restricted access
    response = user.testPost(copyUrl, copyRequest);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    final FlowEntity flowEntity = response.readEntity(FlowEntity.class);
    // remove the restricted processors
    deleteRestrictedComponent(tuple.getKey(), user);
    deleteRestrictedComponent(flowEntity.getFlow().getProcessors().stream().findFirst().orElse(null), user);
}
Also used : Response(javax.ws.rs.core.Response) CopySnippetRequestEntity(org.apache.nifi.web.api.entity.CopySnippetRequestEntity) SnippetEntity(org.apache.nifi.web.api.entity.SnippetEntity) ExecuteCodeRestrictedProcessor(org.apache.nifi.integration.util.ExecuteCodeRestrictedProcessor) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) FlowEntity(org.apache.nifi.web.api.entity.FlowEntity)

Example 60 with ProcessorEntity

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

the class ITProcessorAccessControl method verifyDelete.

private void verifyDelete(final NiFiTestUser user, final String clientId, final int responseCode) throws Exception {
    final ProcessorEntity entity = createProcessor(helper, "Copy");
    // create the entity body
    final Map<String, String> queryParams = new HashMap<>();
    queryParams.put("version", String.valueOf(entity.getRevision().getVersion()));
    queryParams.put("clientId", clientId);
    // perform the request
    Response response = user.testDelete(entity.getUri(), queryParams);
    // ensure the request is failed with a forbidden status code
    assertEquals(responseCode, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity)

Aggregations

ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)60 Response (javax.ws.rs.core.Response)29 Test (org.junit.Test)26 HashMap (java.util.HashMap)20 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)19 HashSet (java.util.HashSet)17 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)17 URI (java.net.URI)16 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)16 Map (java.util.Map)15 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)12 NiFiUserDetails (org.apache.nifi.authorization.user.NiFiUserDetails)11 NiFiAuthenticationToken (org.apache.nifi.web.security.token.NiFiAuthenticationToken)11 Authentication (org.springframework.security.core.Authentication)11 Set (java.util.Set)10 Authorizable (org.apache.nifi.authorization.resource.Authorizable)10 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)10 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 ClusterCoordinator (org.apache.nifi.cluster.coordination.ClusterCoordinator)8