com.wordnik.swagger.annotations.ApiResponse Java Examples
The following examples show how to use
com.wordnik.swagger.annotations.ApiResponse.
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: FlowResource.java From localization_nifi with Apache License 2.0 | 6 votes |
@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 #2
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * 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 #3
Source File: ResourceResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * 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 #4
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Retrieves all the of reporting tasks in this NiFi. * * @return A reportingTasksEntity. */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("reporting-tasks") @ApiOperation( value = "Gets all reporting tasks", response = ReportingTasksEntity.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 getReportingTasks() { authorizeFlow(); if (isReplicateRequest()) { return replicate(HttpMethod.GET); } // get all the reporting tasks final Set<ReportingTaskEntity> reportingTasks = serviceFacade.getReportingTasks(); reportingTaskResource.populateRemainingReportingTaskEntitiesContent(reportingTasks); // create the response entity final ReportingTasksEntity entity = new ReportingTasksEntity(); entity.setReportingTasks(reportingTasks); // generate the response return clusterContext(generateOkResponse(entity)).build(); }
Example #5
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * 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 |
/** * 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 |
/** * 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 #8
Source File: ProvenanceResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Gets the provenance search options for this NiFi. * * @return A provenanceOptionsEntity */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("search-options") @ApiOperation( value = "Gets the searchable attributes for provenance events", response = ProvenanceOptionsEntity.class, authorizations = { @Authorization(value = "Read - /provenance", 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 getSearchOptions() { authorizeProvenanceRequest(); if (isReplicateRequest()) { return replicate(HttpMethod.GET); } // get provenance search options final ProvenanceOptionsDTO searchOptions = serviceFacade.getProvenanceSearchOptions(); // create the response entity final ProvenanceOptionsEntity entity = new ProvenanceOptionsEntity(); entity.setProvenanceOptions(searchOptions); // generate the response return clusterContext(noCache(Response.ok(entity))).build(); }
Example #9
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Retrieves the configuration for the flow. * * @return A flowConfigurationEntity. */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("config") @ApiOperation( value = "Retrieves the configuration for this NiFi flow", response = FlowConfigurationEntity.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 getFlowConfig() { authorizeFlow(); if (isReplicateRequest()) { return replicate(HttpMethod.GET); } final FlowConfigurationEntity entity = serviceFacade.getFlowConfiguration(); return clusterContext(generateOkResponse(entity)).build(); }
Example #10
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Retrieves the types of reporting tasks that this NiFi supports. * * @return A controllerServicesTypesEntity. * @throws InterruptedException if interrupted */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("reporting-task-types") @ApiOperation( value = "Retrieves the types of reporting tasks that this NiFi supports", notes = NON_GUARANTEED_ENDPOINT, response = ReportingTaskTypesEntity.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 getReportingTaskTypes() throws InterruptedException { authorizeFlow(); // create response entity final ReportingTaskTypesEntity entity = new ReportingTaskTypesEntity(); entity.setReportingTaskTypes(serviceFacade.getReportingTaskTypes()); // generate the response return clusterContext(generateOkResponse(entity)).build(); }
Example #11
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Retrieves the types of prioritizers that this NiFi supports. * * @return A prioritizerTypesEntity. * @throws InterruptedException if interrupted */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("prioritizers") @ApiOperation( value = "Retrieves the types of prioritizers that this NiFi supports", notes = NON_GUARANTEED_ENDPOINT, response = PrioritizerTypesEntity.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 getPrioritizers() throws InterruptedException { authorizeFlow(); // create response entity final PrioritizerTypesEntity entity = new PrioritizerTypesEntity(); entity.setPrioritizerTypes(serviceFacade.getWorkQueuePrioritizerTypes()); // generate the response return clusterContext(generateOkResponse(entity)).build(); }
Example #12
Source File: AccessResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * 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 #13
Source File: DataTransferResource.java From localization_nifi with Apache License 2.0 | 5 votes |
@PUT @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("output-ports/{portId}/transactions/{transactionId}") @ApiOperation( value = "Extend transaction TTL", response = TransactionResultEntity.class, authorizations = { @Authorization(value = "Write - /data-transfer/output-ports/{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."), @ApiResponse(code = 503, message = "NiFi instance is not ready for serving request, or temporarily overloaded. Retrying the same request later may be successful"), } ) public Response extendOutputPortTransactionTTL( @PathParam("portId") String portId, @PathParam("transactionId") String transactionId, @Context HttpServletRequest req, @Context HttpServletResponse res, @Context ServletContext context, @Context UriInfo uriInfo, InputStream inputStream) { // authorize access serviceFacade.authorizeAccess(lookup -> { authorizeDataTransfer(lookup, ResourceType.OutputPort, portId); }); return extendPortTransactionTTL(PORT_TYPE_OUTPUT, portId, transactionId, req, res, context, uriInfo, inputStream); }
Example #14
Source File: DataTransferResource.java From localization_nifi with Apache License 2.0 | 5 votes |
@PUT @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("input-ports/{portId}/transactions/{transactionId}") @ApiOperation( value = "Extend transaction TTL", response = TransactionResultEntity.class, authorizations = { @Authorization(value = "Write - /data-transfer/input-ports/{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 extendInputPortTransactionTTL( @PathParam("portId") String portId, @PathParam("transactionId") String transactionId, @Context HttpServletRequest req, @Context HttpServletResponse res, @Context ServletContext context, @Context UriInfo uriInfo, InputStream inputStream) { // authorize access serviceFacade.authorizeAccess(lookup -> { authorizeDataTransfer(lookup, ResourceType.InputPort, portId); }); return extendPortTransactionTTL(PORT_TYPE_INPUT, portId, transactionId, req, res, context, uriInfo, inputStream); }
Example #15
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * 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 #16
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Retrieves the specified remote process groups status history. * * @param id The id of the remote process group to retrieve the status fow. * @return A statusHistoryEntity. * @throws InterruptedException if interrupted */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("remote-process-groups/{id}/status/history") @ApiOperation( value = "Gets the status history", 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 getRemoteProcessGroupStatusHistory( @ApiParam( value = "The remote process group 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.getRemoteProcessGroupStatusHistory(id); return clusterContext(generateOkResponse(entity)).build(); }
Example #17
Source File: ReportingTaskResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Gets the state for a reporting task. * * @param id The id of the reporting task * @return a componentStateEntity */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("{id}/state") @ApiOperation( value = "Gets the state for a reporting task", response = ComponentStateDTO.class, authorizations = { @Authorization(value = "Write - /reporting-tasks/{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 getState( @ApiParam( value = "The reporting task id.", required = true ) @PathParam("id") final String id) { if (isReplicateRequest()) { return replicate(HttpMethod.GET); } // authorize access serviceFacade.authorizeAccess(lookup -> { final Authorizable reportingTask = lookup.getReportingTask(id).getAuthorizable(); reportingTask.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser()); }); // get the component state final ComponentStateDTO state = serviceFacade.getReportingTaskState(id); // generate the response entity final ComponentStateEntity entity = new ComponentStateEntity(); entity.setComponentState(state); // generate the response return clusterContext(generateOkResponse(entity)).build(); }
Example #18
Source File: AccessPolicyResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * 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 #19
Source File: ProcessGroupResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Retrieves the contents of the specified group. * * @param groupId The id of the process group. * @return A processGroupEntity. */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("{id}") @ApiOperation( value = "Gets a process group", response = ProcessGroupEntity.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 getProcessGroup( @ApiParam( value = "The process group id.", required = false ) @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 this process group contents final ProcessGroupEntity entity = serviceFacade.getProcessGroup(groupId); populateRemainingProcessGroupEntityContent(entity); if (entity.getComponent() != null) { entity.getComponent().setContents(null); } return clusterContext(generateOkResponse(entity)).build(); }
Example #20
Source File: ReportingTaskResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Returns the descriptor for the specified property. * * @param id The id of the reporting task. * @param propertyName The property * @return a propertyDescriptorEntity */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("{id}/descriptors") @ApiOperation( value = "Gets a reporting task property descriptor", response = PropertyDescriptorEntity.class, authorizations = { @Authorization(value = "Read - /reporting-tasks/{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 = "The reporting task id.", required = true ) @PathParam("id") final String id, @ApiParam( value = "The property name.", required = true ) @QueryParam("propertyName") final String propertyName) { // 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 reportingTask = lookup.getReportingTask(id).getAuthorizable(); reportingTask.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser()); }); // get the property descriptor final PropertyDescriptorDTO descriptor = serviceFacade.getReportingTaskPropertyDescriptor(id, propertyName); // generate the response entity final PropertyDescriptorEntity entity = new PropertyDescriptorEntity(); entity.setPropertyDescriptor(descriptor); // generate the response return clusterContext(generateOkResponse(entity)).build(); }
Example #21
Source File: FunnelResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * 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 #22
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * 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 #23
Source File: ProcessGroupResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Retrieves all the of remote process groups in this NiFi. * * @return A remoteProcessGroupEntity. */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("{id}/remote-process-groups") @ApiOperation( value = "Gets all remote process groups", response = RemoteProcessGroupsEntity.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 getRemoteProcessGroups( @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 all the remote process groups final Set<RemoteProcessGroupEntity> remoteProcessGroups = serviceFacade.getRemoteProcessGroups(groupId); // prune response as necessary for (RemoteProcessGroupEntity remoteProcessGroupEntity : remoteProcessGroups) { if (remoteProcessGroupEntity.getComponent() != null) { remoteProcessGroupEntity.getComponent().setContents(null); } } // create the response entity final RemoteProcessGroupsEntity entity = new RemoteProcessGroupsEntity(); entity.setRemoteProcessGroups(remoteProcessGroupResource.populateRemainingRemoteProcessGroupEntitiesContent(remoteProcessGroups)); // generate the response return clusterContext(generateOkResponse(entity)).build(); }
Example #24
Source File: AccessPolicyResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * 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 #25
Source File: AccessPolicyResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * 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 #26
Source File: ProcessorResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * 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 #27
Source File: ProcessGroupResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Retrieves all the of output ports in this NiFi. * * @return A outputPortsEntity. */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("{id}/output-ports") @ApiOperation( value = "Gets all output ports", response = OutputPortsEntity.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 getOutputPorts( @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 all the output ports final Set<PortEntity> outputPorts = serviceFacade.getOutputPorts(groupId); // create the response entity final OutputPortsEntity entity = new OutputPortsEntity(); entity.setOutputPorts(outputPortResource.populateRemainingOutputPortEntitiesContent(outputPorts)); // generate the response return clusterContext(generateOkResponse(entity)).build(); }
Example #28
Source File: ControllerServiceResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Retrieves the references of the specified controller service. * * @param id The id of the controller service to retrieve * @return A controllerServiceEntity. */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("{id}/references") @ApiOperation( value = "Gets a controller service", response = ControllerServiceEntity.class, authorizations = { @Authorization(value = "Read - /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 getControllerServiceReferences( @ApiParam( value = "The controller service id.", required = true ) @PathParam("id") final String id) { if (isReplicateRequest()) { return replicate(HttpMethod.GET); } // authorize access serviceFacade.authorizeAccess(lookup -> { final Authorizable controllerService = lookup.getControllerService(id).getAuthorizable(); controllerService.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser()); }); // get the controller service final ControllerServiceReferencingComponentsEntity entity = serviceFacade.getControllerServiceReferencingComponents(id); return clusterContext(generateOkResponse(entity)).build(); }
Example #29
Source File: SnippetResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * 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 #30
Source File: TenantsResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * 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(); }