Search in sources :

Example 46 with ProcessorEntity

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

the class LocalComponentLifecycle method isProcessorActionComplete.

private boolean isProcessorActionComplete(final Set<ProcessorEntity> processorEntities, final Map<String, AffectedComponentEntity> affectedComponents, final ScheduledState desiredState) {
    final String desiredStateName = desiredState.name();
    // update the affected processors
    processorEntities.stream().filter(entity -> affectedComponents.containsKey(entity.getId())).forEach(entity -> {
        final AffectedComponentEntity affectedComponentEntity = affectedComponents.get(entity.getId());
        affectedComponentEntity.setRevision(entity.getRevision());
        // only consider updating this component if the user had permissions to it
        if (Boolean.TRUE.equals(affectedComponentEntity.getPermissions().getCanRead())) {
            final AffectedComponentDTO affectedComponent = affectedComponentEntity.getComponent();
            affectedComponent.setState(entity.getStatus().getAggregateSnapshot().getRunStatus());
            affectedComponent.setActiveThreadCount(entity.getStatus().getAggregateSnapshot().getActiveThreadCount());
            if (Boolean.TRUE.equals(entity.getPermissions().getCanRead())) {
                affectedComponent.setValidationErrors(entity.getComponent().getValidationErrors());
            }
        }
    });
    final boolean allProcessorsMatch = processorEntities.stream().filter(entity -> affectedComponents.containsKey(entity.getId())).allMatch(entity -> {
        final ProcessorStatusDTO status = entity.getStatus();
        final String runStatus = status.getAggregateSnapshot().getRunStatus();
        final boolean stateMatches = desiredStateName.equalsIgnoreCase(runStatus);
        if (!stateMatches) {
            return false;
        }
        if (desiredState == ScheduledState.STOPPED && status.getAggregateSnapshot().getActiveThreadCount() != 0) {
            return false;
        }
        return true;
    });
    if (!allProcessorsMatch) {
        return false;
    }
    return true;
}
Also used : NiFiServiceFacade(org.apache.nifi.web.NiFiServiceFacade) Revision(org.apache.nifi.web.Revision) Logger(org.slf4j.Logger) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) LoggerFactory(org.slf4j.LoggerFactory) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) Set(java.util.Set) RevisionManager(org.apache.nifi.web.revision.RevisionManager) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) AffectedComponentDTO(org.apache.nifi.web.api.dto.AffectedComponentDTO) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ScheduledState(org.apache.nifi.controller.ScheduledState) Map(java.util.Map) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity) URI(java.net.URI) DtoFactory(org.apache.nifi.web.api.dto.DtoFactory) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) AffectedComponentDTO(org.apache.nifi.web.api.dto.AffectedComponentDTO) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity)

Example 47 with ProcessorEntity

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

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

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

the class ITProcessorAccessControl method testNoneUserGetProcessor.

/**
 * Ensures the NONE user can get a processor.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserGetProcessor() throws Exception {
    final ProcessorEntity entity = getRandomProcessor(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
}
Also used : ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) Test(org.junit.Test)

Example 50 with ProcessorEntity

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

the class ITProcessorAccessControl method testCopyPasteRestrictedProcessor.

/**
 * Tests attempting to copy/paste a restricted processor.
 *
 * @throws Exception ex
 */
@Test
public void testCopyPasteRestrictedProcessor() throws Exception {
    final String copyUrl = helper.getBaseUrl() + "/process-groups/root/snippet-instance";
    final Tuple<ProcessorEntity, SnippetEntity> tuple = createSnippetWithRestrictedComponent(RestrictedProcessor.class.getName(), helper.getPrivilegedUser());
    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 = helper.getExecuteCodeUser().testPost(copyUrl, copyRequest);
    // ensure the request is successful
    assertEquals(403, response.getStatus());
    // create the snippet
    response = helper.getPrivilegedUser().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(), helper.getPrivilegedUser());
    deleteRestrictedComponent(flowEntity.getFlow().getProcessors().stream().findFirst().orElse(null), helper.getPrivilegedUser());
}
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) RestrictedProcessor(org.apache.nifi.integration.util.RestrictedProcessor) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) FlowEntity(org.apache.nifi.web.api.entity.FlowEntity) Test(org.junit.Test)

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