com.wordnik.swagger.annotations.ApiOperation Java Examples

The following examples show how to use com.wordnik.swagger.annotations.ApiOperation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccessResource.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the access configuration for this NiFi.
 *
 * @param httpServletRequest the servlet request
 * @return A accessConfigurationEntity
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("config")
@ApiOperation(
        value = "Retrieves the access configuration for this NiFi",
        response = AccessConfigurationEntity.class
)
public Response getLoginConfig(@Context HttpServletRequest httpServletRequest) {

    final AccessConfigurationDTO accessConfiguration = new AccessConfigurationDTO();

    // specify whether login should be supported and only support for secure requests
    accessConfiguration.setSupportsLogin(loginIdentityProvider != null && httpServletRequest.isSecure());

    // create the response entity
    final AccessConfigurationEntity entity = new AccessConfigurationEntity();
    entity.setConfig(accessConfiguration);

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #2
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.TEXT_PLAIN)
@Path("client-id")
@ApiOperation(
        value = "Generates a client id.",
        response = String.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = "")
        }
)
@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 = 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 generateClientId() {
    authorizeFlow();
    return clusterContext(generateOkResponse(generateUuid())).build();
}
 
Example #3
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the status for this NiFi.
 *
 * @return A controllerStatusEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("status")
@ApiOperation(
        value = "Gets the current status of this NiFi",
        response = ControllerStatusEntity.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = "")
        }
)
@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 = 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 getControllerStatus() throws InterruptedException {

    authorizeFlow();

    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    final ControllerStatusDTO controllerStatus = serviceFacade.getControllerStatus();

    // create the response entity
    final ControllerStatusEntity entity = new ControllerStatusEntity();
    entity.setControllerStatus(controllerStatus);

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #4
Source File: ResourceResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the available resources that support access/authorization policies.
 *
 * @return A resourcesEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
        value = "Gets the available resources that support access/authorization policies",
        response = ResourcesEntity.class,
        authorizations = {
                @Authorization(value = "Read - /resources", type = "")
        }
)
@ApiResponses(
        value = {
                @ApiResponse(code = 401, message = "Client could not be authenticated."),
                @ApiResponse(code = 403, message = "Client is not authorized to make this request."),}
)
public Response getResources() {

    authorizeResource();

    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    final List<ResourceDTO> resources = serviceFacade.getResources();

    // create the response
    final ResourcesEntity entity = new ResourcesEntity();
    entity.setResources(resources);

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #5
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the specified connection status history.
 *
 * @param id The id of the connection to retrieve.
 * @return A statusHistoryEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("connections/{id}/status/history")
@ApiOperation(
        value = "Gets the status history for a connection",
        response = StatusHistoryEntity.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = "")
        }
)
@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 getConnectionStatusHistory(
        @ApiParam(
                value = "The connection id.",
                required = true
        )
        @PathParam("id") String id) throws InterruptedException {

    authorizeFlow();

    // replicate if cluster manager
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    // get the specified processor status history
    final StatusHistoryEntity entity = serviceFacade.getConnectionStatusHistory(id);
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #6
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the contents of the specified group.
 *
 * @param groupId The id of the process group.
 * @return A processGroupEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("process-groups/{id}")
@ApiOperation(
        value = "Gets a process group",
        response = ProcessGroupFlowEntity.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = "")
        }
)
@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 getFlow(
        @ApiParam(
                value = "The process group id.",
                required = false
        )
        @PathParam("id") String groupId) throws InterruptedException {

    authorizeFlow();

    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    // get this process group flow
    final ProcessGroupFlowEntity entity = serviceFacade.getProcessGroupFlow(groupId);
    populateRemainingFlowContent(entity.getProcessGroupFlow());
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #7
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the specified remote process groups status history.
 *
 * @param groupId The group id
 * @return A processorEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("process-groups/{id}/status/history")
@ApiOperation(
        value = "Gets status history for a remote process group",
        response = StatusHistoryEntity.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = "")
        }
)
@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 getProcessGroupStatusHistory(
        @ApiParam(
                value = "The process group id.",
                required = true
        )
        @PathParam("id") String groupId) throws InterruptedException {

    authorizeFlow();

    // replicate if cluster manager
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    // get the specified processor status history
    final StatusHistoryEntity entity = serviceFacade.getProcessGroupStatusHistory(groupId);
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #8
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves all the of controller services in this NiFi.
 *
 * @return A controllerServicesEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("controller/controller-services")
@ApiOperation(
        value = "Gets all controller services",
        response = ControllerServicesEntity.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = "")
        }
)
@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 = 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 getControllerServicesFromController() {

    authorizeFlow();

    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    // get all the controller services
    final Set<ControllerServiceEntity> controllerServices = serviceFacade.getControllerServices(null);
    controllerServiceResource.populateRemainingControllerServiceEntitiesContent(controllerServices);

    // create the response entity
    final ControllerServicesEntity entity = new ControllerServicesEntity();
    entity.setCurrentTime(new Date());
    entity.setControllerServices(controllerServices);

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #9
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the specified processor status history.
 *
 * @param id The id of the processor history to retrieve.
 * @return A statusHistoryEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("processors/{id}/status/history")
@ApiOperation(
        value = "Gets status history for a processor",
        response = StatusHistoryEntity.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = "")
        }
)
@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 getProcessorStatusHistory(
        @ApiParam(
                value = "The processor id.",
                required = true
        )
        @PathParam("id") String id) throws InterruptedException {

    authorizeFlow();

    // replicate if cluster manager
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    // get the specified processor status history
    final StatusHistoryEntity entity = serviceFacade.getProcessorStatusHistory(id);
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #10
Source File: AccessResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a single use access token for accessing a NiFi UI extension.
 *
 * @param httpServletRequest the servlet request
 * @return A token (string)
 */
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN)
@Path("/ui-extension-token")
@ApiOperation(
        value = "Creates a single use access token for accessing a NiFi UI extension.",
        notes = "The token returned is a base64 encoded string. It is valid for a single request up to five minutes from being issued. " +
                "It is used as a query parameter name 'access_token'.",
        response = String.class
)
@ApiResponses(
        value = {
                @ApiResponse(code = 403, message = "Client is not authorized to make this request."),
                @ApiResponse(code = 409, message = "Unable to create the download token because NiFi is not in the appropriate state. " +
                        "(i.e. may not have any tokens to grant or be configured to support username/password login)"),
                @ApiResponse(code = 500, message = "Unable to create download token because an unexpected error occurred.")
        }
)
public Response createUiExtensionToken(@Context HttpServletRequest httpServletRequest) {
    // only support access tokens when communicating over HTTPS
    if (!httpServletRequest.isSecure()) {
        throw new IllegalStateException("UI extension access tokens are only issued over HTTPS.");
    }

    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    if (user == null) {
        throw new AccessDeniedException("No user authenticated in the request.");
    }

    final OtpAuthenticationToken authenticationToken = new OtpAuthenticationToken(user.getIdentity());

    // generate otp for response
    final String token = otpService.generateUiExtensionToken(authenticationToken);

    // build the response
    final URI uri = URI.create(generateResourceUri("access", "ui-extension-token"));
    return generateCreatedResponse(uri, token).build();
}
 
Example #11
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the controller level bulletins.
 *
 * @return A controllerBulletinsEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("controller/bulletins")
@ApiOperation(
        value = "Retrieves Controller level bulletins",
        response = ControllerBulletinsEntity.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = ""),
                @Authorization(value = "Read - /controller - For controller bulletins", type = ""),
                @Authorization(value = "Read - /controller-services/{uuid} - For controller service bulletins", type = ""),
                @Authorization(value = "Read - /reporting-tasks/{uuid} - For reporting task bulletins", type = "")
        }
)
@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 getBulletins() {

    authorizeFlow();

    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    final ControllerBulletinsEntity entity = serviceFacade.getControllerBulletins();
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #12
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the banners for this NiFi.
 *
 * @return A bannerEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("banners")
@ApiOperation(
        value = "Retrieves the banners for this NiFi",
        response = BannerEntity.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = "")
        }
)
@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 = 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 getBanners() {

    authorizeFlow();

    // get the banner from the properties - will come from the NCM when clustered
    final String bannerText = getProperties().getBannerText();

    // create the DTO
    final BannerDTO bannerDTO = new BannerDTO();
    bannerDTO.setHeaderText(bannerText);
    bannerDTO.setFooterText(bannerText);

    // create the response entity
    final BannerEntity entity = new BannerEntity();
    entity.setBanners(bannerDTO);

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #13
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the types of processors that this NiFi supports.
 *
 * @return A processorTypesEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("processor-types")
@ApiOperation(
        value = "Retrieves the types of processors that this NiFi supports",
        notes = NON_GUARANTEED_ENDPOINT,
        response = ProcessorTypesEntity.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = "")
        }
)
@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 = 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 getProcessorTypes() throws InterruptedException {
    authorizeFlow();

    // create response entity
    final ProcessorTypesEntity entity = new ProcessorTypesEntity();
    entity.setProcessorTypes(serviceFacade.getProcessorTypes());

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #14
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the types of controller services that this NiFi supports.
 *
 * @param serviceType Returns only services that implement this type
 * @return A controllerServicesTypesEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("controller-service-types")
@ApiOperation(
        value = "Retrieves the types of controller services that this NiFi supports",
        notes = NON_GUARANTEED_ENDPOINT,
        response = ControllerServiceTypesEntity.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = "")
        }
)
@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 = 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 getControllerServiceTypes(
        @ApiParam(
                value = "If specified, will only return controller services of this type.",
                required = false
        )
        @QueryParam("serviceType") String serviceType) throws InterruptedException {

    authorizeFlow();

    // create response entity
    final ControllerServiceTypesEntity entity = new ControllerServiceTypesEntity();
    entity.setControllerServiceTypes(serviceFacade.getControllerServiceTypes(serviceType));

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #15
Source File: AccessResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a single use access token for downloading FlowFile content.
 *
 * @param httpServletRequest the servlet request
 * @return A token (string)
 */
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_PLAIN)
@Path("/download-token")
@ApiOperation(
        value = "Creates a single use access token for downloading FlowFile content.",
        notes = "The token returned is a base64 encoded string. It is valid for a single request up to five minutes from being issued. " +
                "It is used as a query parameter name 'access_token'.",
        response = String.class
)
@ApiResponses(
        value = {
                @ApiResponse(code = 403, message = "Client is not authorized to make this request."),
                @ApiResponse(code = 409, message = "Unable to create the download token because NiFi is not in the appropriate state. " +
                        "(i.e. may not have any tokens to grant or be configured to support username/password login)"),
                @ApiResponse(code = 500, message = "Unable to create download token because an unexpected error occurred.")
        }
)
public Response createDownloadToken(@Context HttpServletRequest httpServletRequest) {
    // only support access tokens when communicating over HTTPS
    if (!httpServletRequest.isSecure()) {
        throw new IllegalStateException("Download tokens are only issued over HTTPS.");
    }

    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    if (user == null) {
        throw new AccessDeniedException("No user authenticated in the request.");
    }

    final OtpAuthenticationToken authenticationToken = new OtpAuthenticationToken(user.getIdentity());

    // generate otp for response
    final String token = otpService.generateDownloadToken(authenticationToken);

    // build the response
    final URI uri = URI.create(generateResourceUri("access", "download-token"));
    return generateCreatedResponse(uri, token).build();
}
 
Example #16
Source File: ControllerResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the configuration for this NiFi.
 *
 * @return A controllerConfigurationEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("config")
@ApiOperation(
        value = "Retrieves the configuration for this NiFi Controller",
        response = ControllerConfigurationEntity.class,
        authorizations = {
                @Authorization(value = "Read - /controller", type = "")
        }
)
@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 = 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 getControllerConfig() {

    authorizeController(RequestAction.READ);

    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    final ControllerConfigurationEntity entity = serviceFacade.getControllerConfiguration();
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #17
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieves all the of controller services in this NiFi.
 *
 * @return A controllerServicesEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("process-groups/{id}/controller-services")
@ApiOperation(
        value = "Gets all controller services",
        response = ControllerServicesEntity.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = "")
        }
)
@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 = 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 getControllerServicesFromGroup(
        @ApiParam(
                value = "The process group id.",
                required = true
        )
        @PathParam("id") String groupId) throws InterruptedException {

    authorizeFlow();

    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    // get all the controller services
    final Set<ControllerServiceEntity> controllerServices = serviceFacade.getControllerServices(groupId);
    controllerServiceResource.populateRemainingControllerServiceEntitiesContent(controllerServices);

    // create the response entity
    final ControllerServicesEntity entity = new ControllerServicesEntity();
    entity.setCurrentTime(new Date());
    entity.setControllerServices(controllerServices);

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #18
Source File: AccessPolicyResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieves the specified access policy.
 *
 * @param id The id of the access policy to retrieve
 * @return An accessPolicyEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(
        value = "Gets an access policy",
        response = AccessPolicyEntity.class,
        authorizations = {
                @Authorization(value = "Read - /policies/{resource}", type = "")
        }
)
@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 getAccessPolicy(
        @ApiParam(
                value = "The access policy id.",
                required = true
        )
        @PathParam("id") final String id) {

    // ensure we're running with a configurable authorizer
    if (!(authorizer instanceof AbstractPolicyBasedAuthorizer)) {
        throw new IllegalStateException(AccessPolicyDAO.MSG_NON_ABSTRACT_POLICY_BASED_AUTHORIZER);
    }

    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        Authorizable authorizable = lookup.getAccessPolicyById(id);
        authorizable.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    });

    // get the access policy
    final AccessPolicyEntity entity = serviceFacade.getAccessPolicy(id);
    populateRemainingAccessPolicyEntityContent(entity);

    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #19
Source File: AccessPolicyResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Updates an access policy.
 *
 * @param httpServletRequest request
 * @param id                 The id of the access policy to update.
 * @param requestAccessPolicyEntity An accessPolicyEntity.
 * @return An accessPolicyEntity.
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(
        value = "Updates a access policy",
        response = AccessPolicyEntity.class,
        authorizations = {
                @Authorization(value = "Write - /policies/{resource}", type = "")
        }
)
@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 updateAccessPolicy(
        @Context final HttpServletRequest httpServletRequest,
        @ApiParam(
                value = "The access policy id.",
                required = true
        )
        @PathParam("id") final String id,
        @ApiParam(
                value = "The access policy configuration details.",
                required = true
        ) final AccessPolicyEntity requestAccessPolicyEntity) {

    // ensure we're running with a configurable authorizer
    if (!(authorizer instanceof AbstractPolicyBasedAuthorizer)) {
        throw new IllegalStateException(AccessPolicyDAO.MSG_NON_ABSTRACT_POLICY_BASED_AUTHORIZER);
    }

    if (requestAccessPolicyEntity == null || requestAccessPolicyEntity.getComponent() == null) {
        throw new IllegalArgumentException("Access policy details must be specified.");
    }

    if (requestAccessPolicyEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }

    // ensure the ids are the same
    final AccessPolicyDTO requestAccessPolicyDTO = requestAccessPolicyEntity.getComponent();
    if (!id.equals(requestAccessPolicyDTO.getId())) {
        throw new IllegalArgumentException(String.format("The access policy id (%s) in the request body does not equal the "
                + "access policy id of the requested resource (%s).", requestAccessPolicyDTO.getId(), id));
    }

    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT, requestAccessPolicyEntity);
    }

    // Extract the revision
    final Revision requestRevision = getRevision(requestAccessPolicyEntity, id);
    return withWriteLock(
            serviceFacade,
            requestAccessPolicyEntity,
            requestRevision,
            lookup -> {
                Authorizable authorizable = lookup.getAccessPolicyById(id);
                authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
            },
            null,
            (revision, accessPolicyEntity) -> {
                final AccessPolicyDTO accessPolicyDTO = accessPolicyEntity.getComponent();

                // update the access policy
                final AccessPolicyEntity entity = serviceFacade.updateAccessPolicy(revision, accessPolicyDTO);
                populateRemainingAccessPolicyEntityContent(entity);

                return clusterContext(generateOkResponse(entity)).build();
            }
    );
}
 
Example #20
Source File: AccessPolicyResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Removes the specified access policy.
 *
 * @param httpServletRequest request
 * @param version            The revision is used to verify the client is working with
 *                           the latest version of the flow.
 * @param clientId           Optional client id. If the client id is not specified, a
 *                           new one will be generated. This value (whether specified or generated) is
 *                           included in the response.
 * @param id                 The id of the access policy to remove.
 * @return A entity containing the client id and an updated revision.
 */
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(
        value = "Deletes an access policy",
        response = AccessPolicyEntity.class,
        authorizations = {
                @Authorization(value = "Write - /policies/{resource}", type = ""),
                @Authorization(value = "Write - Policy of the parent resource - /policies/{resource}", type = "")
        }
)
@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 removeAccessPolicy(
        @Context final HttpServletRequest httpServletRequest,
        @ApiParam(
                value = "The revision is used to verify the client is working with the latest version of the flow.",
                required = false
        )
        @QueryParam(VERSION) final LongParameter version,
        @ApiParam(
                value = "If the client id is not specified, new one will be generated. This value (whether specified or generated) is included in the response.",
                required = false
        )
        @QueryParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) final ClientIdParameter clientId,
        @ApiParam(
                value = "The access policy id.",
                required = true
        )
        @PathParam("id") final String id) {

    // ensure we're running with a configurable authorizer
    if (!(authorizer instanceof AbstractPolicyBasedAuthorizer)) {
        throw new IllegalStateException(AccessPolicyDAO.MSG_NON_ABSTRACT_POLICY_BASED_AUTHORIZER);
    }

    if (isReplicateRequest()) {
        return replicate(HttpMethod.DELETE);
    }

    final AccessPolicyEntity requestAccessPolicyEntity = new AccessPolicyEntity();
    requestAccessPolicyEntity.setId(id);

    // handle expects request (usually from the cluster manager)
    final Revision requestRevision = new Revision(version == null ? null : version.getLong(), clientId.getClientId(), id);
    return withWriteLock(
            serviceFacade,
            requestAccessPolicyEntity,
            requestRevision,
            lookup -> {
                final Authorizable accessPolicy = lookup.getAccessPolicyById(id);

                // ensure write permission to the access policy
                accessPolicy.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());

                // ensure write permission to the policy for the parent process group
                accessPolicy.getParentAuthorizable().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
            },
            null,
            (revision, accessPolicyEntity) -> {
                // delete the specified access policy
                final AccessPolicyEntity entity = serviceFacade.deleteAccessPolicy(revision, accessPolicyEntity.getId());
                return clusterContext(generateOkResponse(entity)).build();
            }
    );
}
 
Example #21
Source File: FunnelResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new Funnel.
 *
 * @param httpServletRequest request
 * @param id                 The id of the funnel to update.
 * @param requestFunnelEntity       A funnelEntity.
 * @return A funnelEntity.
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(
        value = "Updates a funnel",
        response = FunnelEntity.class,
        authorizations = {
                @Authorization(value = "Write - /funnels/{uuid}", type = "")
        }
)
@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 updateFunnel(
        @Context final HttpServletRequest httpServletRequest,
        @ApiParam(
                value = "The funnel id.",
                required = true
        )
        @PathParam("id") final String id,
        @ApiParam(
                value = "The funnel configuration details.",
                required = true
        ) final FunnelEntity requestFunnelEntity) {

    if (requestFunnelEntity == null || requestFunnelEntity.getComponent() == null) {
        throw new IllegalArgumentException("Funnel details must be specified.");
    }

    if (requestFunnelEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }

    // ensure the ids are the same
    final FunnelDTO requestFunnelDTO = requestFunnelEntity.getComponent();
    if (!id.equals(requestFunnelDTO.getId())) {
        throw new IllegalArgumentException(String.format("The funnel id (%s) in the request body does not equal the "
                + "funnel id of the requested resource (%s).", requestFunnelDTO.getId(), id));
    }

    final PositionDTO proposedPosition = requestFunnelDTO.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, requestFunnelEntity);
    }

    // Extract the revision
    final Revision requestRevision = getRevision(requestFunnelEntity, id);
    return withWriteLock(
            serviceFacade,
            requestFunnelEntity,
            requestRevision,
            lookup -> {
                Authorizable authorizable = lookup.getFunnel(id);
                authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
            },
            null,
            (revision, funnelEntity) -> {
                // update the funnel
                final FunnelEntity entity = serviceFacade.updateFunnel(revision, funnelEntity.getComponent());
                populateRemainingFunnelEntityContent(entity);

                return clusterContext(generateOkResponse(entity)).build();
            }
    );
}
 
Example #22
Source File: ProcessorResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the specified processor with the specified values.
 *
 * @param httpServletRequest request
 * @param id                 The id of the processor to update.
 * @param requestProcessorEntity    A processorEntity.
 * @return A processorEntity.
 * @throws InterruptedException if interrupted
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}")
@ApiOperation(
        value = "Updates a processor",
        response = ProcessorEntity.class,
        authorizations = {
                @Authorization(value = "Write - /processors/{uuid}", type = ""),
                @Authorization(value = "Read - any referenced Controller Services if this request changes the reference - /controller-services/{uuid}", type = "")
        }
)
@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 updateProcessor(
        @Context final HttpServletRequest httpServletRequest,
        @ApiParam(
                value = "The processor id.",
                required = true
        )
        @PathParam("id") final String id,
        @ApiParam(
                value = "The processor configuration details.",
                required = true
        ) final ProcessorEntity requestProcessorEntity) throws InterruptedException {

    if (requestProcessorEntity == null || requestProcessorEntity.getComponent() == null) {
        throw new IllegalArgumentException("Processor details must be specified.");
    }

    if (requestProcessorEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }

    // ensure the same id is being used
    final ProcessorDTO requestProcessorDTO = requestProcessorEntity.getComponent();
    if (!id.equals(requestProcessorDTO.getId())) {
        throw new IllegalArgumentException(String.format("The processor id (%s) in the request body does "
                + "not equal the processor id of the requested resource (%s).", requestProcessorDTO.getId(), id));
    }

    final PositionDTO proposedPosition = requestProcessorDTO.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, requestProcessorEntity);
    }

    // handle expects request (usually from the cluster manager)
    final Revision requestRevision = getRevision(requestProcessorEntity, id);
    return withWriteLock(
            serviceFacade,
            requestProcessorEntity,
            requestRevision,
            lookup -> {
                final NiFiUser user = NiFiUserUtils.getNiFiUser();

                final ConfigurableComponentAuthorizable authorizable = lookup.getProcessor(id);
                authorizable.getAuthorizable().authorize(authorizer, RequestAction.WRITE, user);

                final ProcessorConfigDTO config = requestProcessorDTO.getConfig();
                if (config != null) {
                    AuthorizeControllerServiceReference.authorizeControllerServiceReferences(config.getProperties(), authorizable, authorizer, lookup);
                }
            },
            () -> serviceFacade.verifyUpdateProcessor(requestProcessorDTO),
            (revision, processorEntity) -> {
                final ProcessorDTO processorDTO = processorEntity.getComponent();

                // update the processor
                final ProcessorEntity entity = serviceFacade.updateProcessor(revision, processorDTO);
                populateRemainingProcessorEntityContent(entity);

                return clusterContext(generateOkResponse(entity)).build();
            }
    );
}
 
Example #23
Source File: FlowResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieves the cluster summary for this NiFi.
 *
 * @return A clusterSummaryEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("cluster/summary")
@ApiOperation(
        value = "The cluster summary for this NiFi",
        response = ClusteSummaryEntity.class,
        authorizations = {
                @Authorization(value = "Read - /flow", type = "")
        }
)
@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 = 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 getClusterSummary() throws InterruptedException {

    authorizeFlow();

    final ClusterSummaryDTO clusterConfiguration = new ClusterSummaryDTO();
    final ClusterCoordinator clusterCoordinator = getClusterCoordinator();

    if (clusterCoordinator != null && clusterCoordinator.isConnected()) {
        final Map<NodeConnectionState, List<NodeIdentifier>> stateMap = clusterCoordinator.getConnectionStates();
        int totalNodeCount = 0;
        for (final List<NodeIdentifier> nodeList : stateMap.values()) {
            totalNodeCount += nodeList.size();
        }
        final List<NodeIdentifier> connectedNodeIds = stateMap.get(NodeConnectionState.CONNECTED);
        final int connectedNodeCount = (connectedNodeIds == null) ? 0 : connectedNodeIds.size();

        clusterConfiguration.setConnectedNodeCount(connectedNodeCount);
        clusterConfiguration.setTotalNodeCount(totalNodeCount);
        clusterConfiguration.setConnectedNodes(connectedNodeCount + " / " + totalNodeCount);
    }

    clusterConfiguration.setClustered(isClustered());
    clusterConfiguration.setConnectedToCluster(isConnectedToCluster());

    // create the response entity
    final ClusteSummaryEntity entity = new ClusteSummaryEntity();
    entity.setClusterSummary(clusterConfiguration);

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #24
Source File: AccessPolicyResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new access policy.
 *
 * @param httpServletRequest request
 * @param requestAccessPolicyEntity An accessPolicyEntity.
 * @return An accessPolicyEntity.
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
        value = "Creates an access policy",
        response = AccessPolicyEntity.class,
        authorizations = {
                @Authorization(value = "Write - /policies/{resource}", type = "")
        }
)
@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 createAccessPolicy(
        @Context final HttpServletRequest httpServletRequest,
        @ApiParam(
                value = "The access policy configuration details.",
                required = true
        ) final AccessPolicyEntity requestAccessPolicyEntity) {

    // ensure we're running with a configurable authorizer
    if (!(authorizer instanceof AbstractPolicyBasedAuthorizer)) {
        throw new IllegalStateException(AccessPolicyDAO.MSG_NON_ABSTRACT_POLICY_BASED_AUTHORIZER);
    }

    if (requestAccessPolicyEntity == null || requestAccessPolicyEntity.getComponent() == null) {
        throw new IllegalArgumentException("Access policy details must be specified.");
    }

    if (requestAccessPolicyEntity.getRevision() == null || (requestAccessPolicyEntity.getRevision().getVersion() == null || requestAccessPolicyEntity.getRevision().getVersion() != 0)) {
        throw new IllegalArgumentException("A revision of 0 must be specified when creating a new Policy.");
    }

    final AccessPolicyDTO requestAccessPolicy = requestAccessPolicyEntity.getComponent();
    if (requestAccessPolicy.getId() != null) {
        throw new IllegalArgumentException("Access policy ID cannot be specified.");
    }

    if (requestAccessPolicy.getResource() == null) {
        throw new IllegalArgumentException("Access policy resource must be specified.");
    }

    // ensure this is a valid action
    RequestAction.valueOfValue(requestAccessPolicy.getAction());

    if (isReplicateRequest()) {
        return replicate(HttpMethod.POST, requestAccessPolicyEntity);
    }

    // handle expects request (usually from the cluster manager)
    return withWriteLock(
            serviceFacade,
            requestAccessPolicyEntity,
            lookup -> {
                final Authorizable accessPolicies = lookup.getAccessPolicyByResource(requestAccessPolicy.getResource());
                accessPolicies.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
            },
            null,
            accessPolicyEntity -> {
                final AccessPolicyDTO accessPolicy = accessPolicyEntity.getComponent();

                // set the access policy id as appropriate
                accessPolicy.setId(generateUuid());

                // get revision from the config
                final RevisionDTO revisionDTO = accessPolicyEntity.getRevision();
                Revision revision = new Revision(revisionDTO.getVersion(), revisionDTO.getClientId(), accessPolicyEntity.getComponent().getId());

                // create the access policy and generate the json
                final AccessPolicyEntity entity = serviceFacade.createAccessPolicy(revision, accessPolicyEntity.getComponent());
                populateRemainingAccessPolicyEntityContent(entity);

                // build the response
                return clusterContext(generateCreatedResponse(URI.create(entity.getUri()), entity)).build();
            }
    );
}
 
Example #25
Source File: ProcessorResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the descriptor for the specified property.
 *
 * @param id           The id of the processor
 * @param propertyName The property
 * @return a propertyDescriptorEntity
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/descriptors")
@ApiOperation(
        value = "Gets the descriptor for a processor property",
        response = PropertyDescriptorEntity.class,
        authorizations = {
                @Authorization(value = "Read - /processors/{uuid}", type = "")
        }
)
@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 getPropertyDescriptor(
        @ApiParam(
                value = "If the client id is not specified, new one will be generated. This value (whether specified or generated) is included in the response.",
                required = false
        )
        @QueryParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) final ClientIdParameter clientId,
        @ApiParam(
                value = "The processor id.",
                required = true
        )
        @PathParam("id") final String id,
        @ApiParam(
                value = "The property name.",
                required = true
        )
        @QueryParam("propertyName") final String propertyName) throws InterruptedException {

    // ensure the property name is specified
    if (propertyName == null) {
        throw new IllegalArgumentException("The property name must be specified.");
    }

    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        final Authorizable processor = lookup.getProcessor(id).getAuthorizable();
        processor.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    });

    // get the property descriptor
    final PropertyDescriptorDTO descriptor = serviceFacade.getProcessorPropertyDescriptor(id, propertyName);

    // generate the response entity
    final PropertyDescriptorEntity entity = new PropertyDescriptorEntity();
    entity.setPropertyDescriptor(descriptor);

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #26
Source File: FunnelResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Removes the specified funnel.
 *
 * @param httpServletRequest request
 * @param version            The revision is used to verify the client is working with
 *                           the latest version of the flow.
 * @param clientId           Optional client id. If the client id is not specified, a
 *                           new one will be generated. This value (whether specified or generated) is
 *                           included in the response.
 * @param id                 The id of the funnel to remove.
 * @return A entity containing the client id and an updated revision.
 */
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(
        value = "Deletes a funnel",
        response = FunnelEntity.class,
        authorizations = {
                @Authorization(value = "Write - /funnels/{uuid}", type = ""),
                @Authorization(value = "Write - Parent Process Group - /process-groups/{uuid}", type = "")
        }
)
@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 removeFunnel(
        @Context final HttpServletRequest httpServletRequest,
        @ApiParam(
                value = "The revision is used to verify the client is working with the latest version of the flow.",
                required = false
        )
        @QueryParam(VERSION) final LongParameter version,
        @ApiParam(
                value = "If the client id is not specified, new one will be generated. This value (whether specified or generated) is included in the response.",
                required = false
        )
        @QueryParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) final ClientIdParameter clientId,
        @ApiParam(
                value = "The funnel id.",
                required = true
        )
        @PathParam("id") final String id) {

    if (isReplicateRequest()) {
        return replicate(HttpMethod.DELETE);
    }

    final FunnelEntity requestFunnelEntity = new FunnelEntity();
    requestFunnelEntity.setId(id);

    // handle expects request (usually from the cluster manager)
    final Revision requestRevision = new Revision(version == null ? null : version.getLong(), clientId.getClientId(), id);
    return withWriteLock(
            serviceFacade,
            requestFunnelEntity,
            requestRevision,
            lookup -> {
                final Authorizable funnel = lookup.getFunnel(id);

                // ensure write permission to the funnel
                funnel.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());

                // ensure write permission to the parent process group
                funnel.getParentAuthorizable().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
            },
            () -> serviceFacade.verifyDeleteFunnel(id),
            (revision, funnelEntity) -> {
                // delete the specified funnel
                final FunnelEntity entity = serviceFacade.deleteFunnel(revision, funnelEntity.getId());
                return clusterContext(generateOkResponse(entity)).build();
            }
    );
}
 
Example #27
Source File: SnippetResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a snippet based off the specified configuration.
 *
 * @param httpServletRequest request
 * @param requestSnippetEntity      A snippetEntity
 * @return A snippetEntity
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
        value = "Creates a snippet. The snippet will be automatically discarded if not used in a subsequent request after 1 minute.",
        response = SnippetEntity.class,
        authorizations = {
                @Authorization(value = "Read or Write - /{component-type}/{uuid} - For every component (all Read or all Write) in the Snippet and their descendant components", type = "")
        }
)
@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 createSnippet(
        @Context HttpServletRequest httpServletRequest,
        @ApiParam(
                value = "The snippet configuration details.",
                required = true
        )
        final SnippetEntity requestSnippetEntity) {

    if (requestSnippetEntity == null || requestSnippetEntity.getSnippet() == null) {
        throw new IllegalArgumentException("Snippet details must be specified.");
    }

    if (requestSnippetEntity.getSnippet().getId() != null) {
        throw new IllegalArgumentException("Snippet ID cannot be specified.");
    }

    if (requestSnippetEntity.getSnippet().getParentGroupId() == null) {
        throw new IllegalArgumentException("The parent Process Group of the snippet must be specified.");
    }

    if (isReplicateRequest()) {
        return replicate(HttpMethod.POST, requestSnippetEntity);
    }

    return withWriteLock(
            serviceFacade,
            requestSnippetEntity,
            lookup -> {
                final SnippetDTO snippetRequest = requestSnippetEntity.getSnippet();

                // the snippet being created may be used later for batch component modifications,
                // copy/paste, or template creation. during those subsequent actions, the snippet
                // will again be authorized accordingly (read or write). at this point we do not
                // know what the snippet will be used for so we need to attempt to authorize as
                // read OR write

                try {
                    authorizeSnippetRequest(snippetRequest, authorizer, lookup, RequestAction.READ);
                } catch (final AccessDeniedException e) {
                    authorizeSnippetRequest(snippetRequest, authorizer, lookup, RequestAction.WRITE);
                }
            },
            null,
            (snippetEntity) -> {
                // set the processor id as appropriate
                snippetEntity.getSnippet().setId(generateUuid());

                // create the snippet
                final SnippetEntity entity = serviceFacade.createSnippet(snippetEntity.getSnippet());
                populateRemainingSnippetEntityContent(entity);

                // build the response
                return clusterContext(generateCreatedResponse(URI.create(entity.getSnippet().getUri()), entity)).build();
            }
    );
}
 
Example #28
Source File: FunnelResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieves the specified funnel.
 *
 * @param id The id of the funnel to retrieve
 * @return A funnelEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(
        value = "Gets a funnel",
        response = FunnelEntity.class,
        authorizations = {
                @Authorization(value = "Read - /funnels/{uuid}", type = "")
        }
)
@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 getFunnel(
        @ApiParam(
                value = "The funnel id.",
                required = true
        )
        @PathParam("id") final String id) {

    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        final Authorizable funnel = lookup.getFunnel(id);
        funnel.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    });

    // get the funnel
    final FunnelEntity entity = serviceFacade.getFunnel(id);
    populateRemainingFunnelEntityContent(entity);

    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #29
Source File: ProcessGroupResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieves all the processors in this NiFi.
 *
 * @param groupId group id
 * @return A processorsEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/processors")
@ApiOperation(
        value = "Gets all processors",
        response = ProcessorsEntity.class,
        authorizations = {
                @Authorization(value = "Read - /process-groups/{uuid}", type = "")
        }
)
@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 getProcessors(
        @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 processors
    final Set<ProcessorEntity> processors = serviceFacade.getProcessors(groupId);

    // create the response entity
    final ProcessorsEntity entity = new ProcessorsEntity();
    entity.setProcessors(processorResource.populateRemainingProcessorEntitiesContent(processors));

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}
 
Example #30
Source File: TenantsResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieves all the of user groups in this NiFi.
 *
 * @return A UserGroupsEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("user-groups")
@ApiOperation(
        value = "Gets all user groups",
        notes = NON_GUARANTEED_ENDPOINT,
        response = UserGroupsEntity.class,
        authorizations = {
                @Authorization(value = "Read - /tenants", type = "")
        }
)
@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 getUserGroups() {

    // ensure we're running with a configurable authorizer
    if (!(authorizer instanceof AbstractPolicyBasedAuthorizer)) {
        throw new IllegalStateException(AccessPolicyDAO.MSG_NON_ABSTRACT_POLICY_BASED_AUTHORIZER);
    }

    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        final Authorizable tenants = lookup.getTenant();
        tenants.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    });

    // get all the user groups
    final Set<UserGroupEntity> users = serviceFacade.getUserGroups();

    // create the response entity
    final UserGroupsEntity entity = new UserGroupsEntity();
    entity.setUserGroups(populateRemainingUserGroupEntitiesContent(users));

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}