Search in sources :

Example 31 with ProcessGroupEntity

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

the class ProcessGroupResource method getProcessGroups.

/**
 * Retrieves all the processors in this NiFi.
 *
 * @return A processorsEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/process-groups")
@ApiOperation(value = "Gets all process groups", response = ProcessGroupsEntity.class, authorizations = { @Authorization(value = "Read - /process-groups/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response getProcessGroups(@ApiParam(value = "The process group id.", required = true) @PathParam("id") final String groupId) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        final Authorizable processGroup = lookup.getProcessGroup(groupId).getAuthorizable();
        processGroup.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    });
    // get the process groups
    final Set<ProcessGroupEntity> entities = serviceFacade.getProcessGroups(groupId);
    // always prune the contents
    for (final ProcessGroupEntity entity : entities) {
        if (entity.getComponent() != null) {
            entity.getComponent().setContents(null);
        }
    }
    // create the response entity
    final ProcessGroupsEntity entity = new ProcessGroupsEntity();
    entity.setProcessGroups(populateRemainingProcessGroupEntitiesContent(entities));
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) ProcessGroupsEntity(org.apache.nifi.web.api.entity.ProcessGroupsEntity) RemoteProcessGroupsEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupsEntity) ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) TemplateContentsAuthorizable(org.apache.nifi.authorization.TemplateContentsAuthorizable) ProcessGroupAuthorizable(org.apache.nifi.authorization.ProcessGroupAuthorizable) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 32 with ProcessGroupEntity

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

the class ProcessGroupResource method updateProcessGroup.

/**
 * Updates the specified process group.
 *
 * @param httpServletRequest request
 * @param id                 The id of the process group.
 * @param requestProcessGroupEntity A processGroupEntity.
 * @return A processGroupEntity.
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Updates a process group", response = ProcessGroupEntity.class, authorizations = { @Authorization(value = "Write - /process-groups/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response updateProcessGroup(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The process group id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The process group configuration details.", required = true) final ProcessGroupEntity requestProcessGroupEntity) {
    if (requestProcessGroupEntity == null || requestProcessGroupEntity.getComponent() == null) {
        throw new IllegalArgumentException("Process group details must be specified.");
    }
    if (requestProcessGroupEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }
    // ensure the same id is being used
    final ProcessGroupDTO requestProcessGroupDTO = requestProcessGroupEntity.getComponent();
    if (!id.equals(requestProcessGroupDTO.getId())) {
        throw new IllegalArgumentException(String.format("The process group id (%s) in the request body does " + "not equal the process group id of the requested resource (%s).", requestProcessGroupDTO.getId(), id));
    }
    final PositionDTO proposedPosition = requestProcessGroupDTO.getPosition();
    if (proposedPosition != null) {
        if (proposedPosition.getX() == null || proposedPosition.getY() == null) {
            throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified.");
        }
    }
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT, requestProcessGroupEntity);
    }
    // handle expects request (usually from the cluster manager)
    final Revision requestRevision = getRevision(requestProcessGroupEntity, id);
    return withWriteLock(serviceFacade, requestProcessGroupEntity, requestRevision, lookup -> {
        Authorizable authorizable = lookup.getProcessGroup(id).getAuthorizable();
        authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, () -> serviceFacade.verifyUpdateProcessGroup(requestProcessGroupDTO), (revision, processGroupEntity) -> {
        // update the process group
        final ProcessGroupEntity entity = serviceFacade.updateProcessGroup(revision, processGroupEntity.getComponent());
        populateRemainingProcessGroupEntityContent(entity);
        return generateOkResponse(entity).build();
    });
}
Also used : ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) Revision(org.apache.nifi.web.Revision) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) TemplateContentsAuthorizable(org.apache.nifi.authorization.TemplateContentsAuthorizable) ProcessGroupAuthorizable(org.apache.nifi.authorization.ProcessGroupAuthorizable) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 33 with ProcessGroupEntity

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

the class ITProcessGroupAccessControl method testReadUserGetProcessGroup.

/**
 * Ensures the READ user can get a process group.
 *
 * @throws Exception ex
 */
@Test
public void testReadUserGetProcessGroup() throws Exception {
    final ProcessGroupEntity entity = getRandomProcessGroup(helper.getReadUser());
    assertTrue(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNotNull(entity.getComponent());
}
Also used : ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) Test(org.junit.Test)

Example 34 with ProcessGroupEntity

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

the class ITProcessGroupAccessControl method verifyDelete.

private void verifyDelete(final NiFiTestUser user, final String clientId, final int responseCode) throws Exception {
    final ProcessGroupEntity entity = createProcessGroup("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) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) HashMap(java.util.HashMap)

Example 35 with ProcessGroupEntity

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

the class ITProcessGroupAccessControl method testNoneUserPutProcessGroup.

/**
 * Ensures the NONE user cannot put a process group.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutProcessGroup() throws Exception {
    final ProcessGroupEntity entity = getRandomProcessGroup(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
    final String updatedName = "Updated Name" + count++;
    // attempt to update the name
    final ProcessGroupDTO requestDto = new ProcessGroupDTO();
    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 ProcessGroupEntity requestEntity = new ProcessGroupEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);
    // perform the request
    final Response response = updateProcessGroup(helper.getNoneUser(), requestEntity);
    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Test(org.junit.Test)

Aggregations

ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)37 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)17 Response (javax.ws.rs.core.Response)15 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)15 RemoteProcessGroupEntity (org.apache.nifi.web.api.entity.RemoteProcessGroupEntity)15 Authorizable (org.apache.nifi.authorization.resource.Authorizable)14 ApiOperation (io.swagger.annotations.ApiOperation)11 ApiResponses (io.swagger.annotations.ApiResponses)11 Consumes (javax.ws.rs.Consumes)11 Path (javax.ws.rs.Path)11 Produces (javax.ws.rs.Produces)11 ComponentAuthorizable (org.apache.nifi.authorization.ComponentAuthorizable)10 ProcessGroupAuthorizable (org.apache.nifi.authorization.ProcessGroupAuthorizable)10 HashMap (java.util.HashMap)9 Map (java.util.Map)9 Test (org.junit.Test)9 VersionControlInformationDTO (org.apache.nifi.web.api.dto.VersionControlInformationDTO)8 FlowDTO (org.apache.nifi.web.api.dto.flow.FlowDTO)8 Set (java.util.Set)7 Bucket (org.apache.nifi.registry.bucket.Bucket)7