com.wordnik.swagger.annotations.ApiResponses Java Examples
The following examples show how to use
com.wordnik.swagger.annotations.ApiResponses.
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 | 5 votes |
/** * 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 #2
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 #3
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 #4
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 #5
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * 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 #6
Source File: AccessResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * 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 #7
Source File: ControllerResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * 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 #8
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * 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 #9
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 #10
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * 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 #11
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 #12
Source File: FlowFileQueueResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Checks the status of an outstanding listing request. * * @param connectionId The id of the connection * @param listingRequestId The id of the drop request * @return A dropRequestEntity */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("{id}/listing-requests/{listing-request-id}") @ApiOperation( value = "Gets the current status of a listing request for the specified connection.", response = ListingRequestEntity.class, authorizations = { @Authorization(value = "Read Source Data - /data/{component-type}/{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 getListingRequest( @ApiParam( value = "The connection id.", required = true ) @PathParam("id") final String connectionId, @ApiParam( value = "The listing request id.", required = true ) @PathParam("listing-request-id") final String listingRequestId) { if (isReplicateRequest()) { return replicate(HttpMethod.GET); } // authorize access serviceFacade.authorizeAccess(lookup -> { final ConnectionAuthorizable connAuth = lookup.getConnection(connectionId); final Authorizable dataAuthorizable = connAuth.getSourceData(); dataAuthorizable.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser()); }); // get the listing request final ListingRequestDTO listingRequest = serviceFacade.getFlowFileListingRequest(connectionId, listingRequestId); populateRemainingFlowFileListingContent(connectionId, listingRequest); // create the response entity final ListingRequestEntity entity = new ListingRequestEntity(); entity.setListingRequest(listingRequest); return generateOkResponse(entity).build(); }
Example #13
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 #14
Source File: AccessPolicyResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * 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 #15
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 #16
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 #17
Source File: ControllerServiceResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Removes the specified controller service. * * @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 controller service 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 controller service", response = ControllerServiceEntity.class, authorizations = { @Authorization(value = "Write - /controller-services/{uuid}", type = ""), @Authorization(value = "Write - Parent Process Group if scoped by Process Group - /process-groups/{uuid}", type = ""), @Authorization(value = "Write - Controller if scoped by Controller - /controller", type = ""), @Authorization(value = "Read - any referenced Controller Services - /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 removeControllerService( @Context 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 controller service id.", required = true ) @PathParam("id") final String id) { if (isReplicateRequest()) { return replicate(HttpMethod.DELETE); } final ControllerServiceEntity requestControllerServiceEntity = new ControllerServiceEntity(); requestControllerServiceEntity.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, requestControllerServiceEntity, requestRevision, lookup -> { final ConfigurableComponentAuthorizable controllerService = lookup.getControllerService(id); // ensure write permission to the controller service controllerService.getAuthorizable().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser()); // ensure write permission to the parent process group controllerService.getAuthorizable().getParentAuthorizable().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser()); // verify any referenced services AuthorizeControllerServiceReference.authorizeControllerServiceReferences(controllerService, authorizer, lookup, false); }, () -> serviceFacade.verifyDeleteControllerService(id), (revision, controllerServiceEntity) -> { // delete the specified controller service final ControllerServiceEntity entity = serviceFacade.deleteControllerService(revision, controllerServiceEntity.getId()); return clusterContext(generateOkResponse(entity)).build(); } ); }
Example #18
Source File: FlowResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * 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 #19
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 #20
Source File: TenantsResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Updates a user group. * * @param httpServletRequest request * @param id The id of the user group to update. * @param requestUserGroupEntity An userGroupEntity. * @return An userGroupEntity. */ @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("user-groups/{id}") @ApiOperation( value = "Updates a user group", notes = NON_GUARANTEED_ENDPOINT, response = UserGroupEntity.class, authorizations = { @Authorization(value = "Write - /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 updateUserGroup( @Context final HttpServletRequest httpServletRequest, @ApiParam( value = "The user group id.", required = true ) @PathParam("id") final String id, @ApiParam( value = "The user group configuration details.", required = true ) final UserGroupEntity requestUserGroupEntity) { // ensure we're running with a configurable authorizer if (!(authorizer instanceof AbstractPolicyBasedAuthorizer)) { throw new IllegalStateException(AccessPolicyDAO.MSG_NON_ABSTRACT_POLICY_BASED_AUTHORIZER); } if (requestUserGroupEntity == null || requestUserGroupEntity.getComponent() == null) { throw new IllegalArgumentException("User group details must be specified."); } if (requestUserGroupEntity.getRevision() == null) { throw new IllegalArgumentException("Revision must be specified."); } // ensure the ids are the same final UserGroupDTO requestUserGroupDTO = requestUserGroupEntity.getComponent(); if (!id.equals(requestUserGroupDTO.getId())) { throw new IllegalArgumentException(String.format("The user group id (%s) in the request body does not equal the " + "user group id of the requested resource (%s).", requestUserGroupDTO.getId(), id)); } if (isReplicateRequest()) { return replicate(HttpMethod.PUT, requestUserGroupEntity); } // Extract the revision final Revision requestRevision = getRevision(requestUserGroupEntity, id); return withWriteLock( serviceFacade, requestUserGroupEntity, requestRevision, lookup -> { final Authorizable tenants = lookup.getTenant(); tenants.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser()); }, null, (revision, userGroupEntity) -> { // update the user group final UserGroupEntity entity = serviceFacade.updateUserGroup(revision, userGroupEntity.getComponent()); populateRemainingUserGroupEntityContent(entity); return clusterContext(generateOkResponse(entity)).build(); } ); }
Example #21
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 #22
Source File: AccessPolicyResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Retrieves the specified access policy. * * @return An accessPolicyEntity. */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("{action}/{resource: .+}") @ApiOperation( value = "Gets an access policy for the specified action and resource", notes = "Will return the effective policy if no component specific policy exists for the specified action and resource. " + "Must have Read permissions to the policy with the desired action and resource. Permissions for the policy that is " + "returned will be indicated in the response. This means the client could be authorized to get the policy for a " + "given component but the effective policy may be inherited from an ancestor Process Group. If the client does not " + "have permissions to that policy, the response will not include the policy and the permissions in the response " + "will be marked accordingly. If the client does not have permissions to the policy of the desired action and resource " + "a 403 response will be returned.", 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 getAccessPolicyForResource( @ApiParam( value = "The request action.", allowableValues = "read, write", required = true ) @PathParam("action") final String action, @ApiParam( value = "The resource of the policy.", required = true ) @PathParam("resource") String rawResource) { // ensure we're running with a configurable authorizer if (!(authorizer instanceof AbstractPolicyBasedAuthorizer)) { throw new IllegalStateException(AccessPolicyDAO.MSG_NON_ABSTRACT_POLICY_BASED_AUTHORIZER); } // parse the action and resource type final RequestAction requestAction = RequestAction.valueOfValue(action); final String resource = "/" + rawResource; if (isReplicateRequest()) { return replicate(HttpMethod.GET); } // authorize access serviceFacade.authorizeAccess(lookup -> { final Authorizable accessPolicy = lookup.getAccessPolicyByResource(resource); accessPolicy.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser()); }); // get the access policy final AccessPolicyEntity entity = serviceFacade.getAccessPolicy(requestAction, resource); populateRemainingAccessPolicyEntityContent(entity); return clusterContext(generateOkResponse(entity)).build(); }
Example #23
Source File: ProcessGroupResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Gets all the connections. * * @return A connectionsEntity. */ @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("{id}/connections") @ApiOperation( value = "Gets all connections", response = ConnectionsEntity.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 getConnections( @ApiParam( value = "The process group id.", required = true ) @PathParam("id") 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()); }); // all of the relationships for the specified source processor Set<ConnectionEntity> connections = serviceFacade.getConnections(groupId); // create the client response entity ConnectionsEntity entity = new ConnectionsEntity(); entity.setConnections(connectionResource.populateRemainingConnectionEntitiesContent(connections)); // generate the response return clusterContext(generateOkResponse(entity)).build(); }
Example #24
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 #25
Source File: FunnelResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * 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 #26
Source File: FunnelResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * 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 #27
Source File: AccessResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Creates a token for accessing the REST API via username/password. * * @param httpServletRequest the servlet request * @param username the username * @param password the password * @return A JWT (string) */ @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.TEXT_PLAIN) @Path("/token") @ApiOperation( value = "Creates a token for accessing the REST API via username/password", notes = "The token returned is formatted as a JSON Web Token (JWT). The token is base64 encoded and comprised of three parts. The header, " + "the body, and the signature. The expiration of the token is a contained within the body. The token can be used in the Authorization header " + "in the format 'Authorization: Bearer <token>'.", response = String.class ) @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 = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "Unable to create access token because NiFi is not in the appropriate state. (i.e. may not be configured to support username/password login."), @ApiResponse(code = 500, message = "Unable to create access token because an unexpected error occurred.") } ) public Response createAccessToken( @Context HttpServletRequest httpServletRequest, @FormParam("username") String username, @FormParam("password") String password) { // only support access tokens when communicating over HTTPS if (!httpServletRequest.isSecure()) { throw new IllegalStateException("Access tokens are only issued over HTTPS."); } // if not configuration for login, don't consider credentials if (loginIdentityProvider == null) { throw new IllegalStateException("Username/Password login not supported by this NiFi."); } final LoginAuthenticationToken loginAuthenticationToken; // ensure we have login credentials if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) { throw new IllegalArgumentException("The username and password must be specified."); } try { // attempt to authenticate final AuthenticationResponse authenticationResponse = loginIdentityProvider.authenticate(new LoginCredentials(username, password)); long expiration = validateTokenExpiration(authenticationResponse.getExpiration(), authenticationResponse.getIdentity()); // create the authentication token loginAuthenticationToken = new LoginAuthenticationToken(authenticationResponse.getIdentity(), expiration, authenticationResponse.getIssuer()); } catch (final InvalidLoginCredentialsException ilce) { throw new IllegalArgumentException("The supplied username and password are not valid.", ilce); } catch (final IdentityAccessException iae) { throw new AdministrationException(iae.getMessage(), iae); } // generate JWT for response final String token = jwtService.generateSignedToken(loginAuthenticationToken); // build the response final URI uri = URI.create(generateResourceUri("access", "token")); return generateCreatedResponse(uri, token).build(); }
Example #28
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 #29
Source File: TenantsResource.java From localization_nifi with Apache License 2.0 | 4 votes |
/** * Removes the specified user group. * * @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 user group to remove. * @return A entity containing the client id and an updated revision. */ @DELETE @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @Path("user-groups/{id}") @ApiOperation( value = "Deletes a user group", notes = NON_GUARANTEED_ENDPOINT, response = UserGroupEntity.class, authorizations = { @Authorization(value = "Write - /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 removeUserGroup( @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 user group 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 UserGroupEntity requestUserGroupEntity = new UserGroupEntity(); requestUserGroupEntity.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, requestUserGroupEntity, requestRevision, lookup -> { final Authorizable tenants = lookup.getTenant(); tenants.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser()); }, null, (revision, userGroupEntity) -> { // delete the specified user group final UserGroupEntity entity = serviceFacade.deleteUserGroup(revision, userGroupEntity.getId()); return clusterContext(generateOkResponse(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(); }