Search in sources :

Example 41 with Revision

use of org.apache.nifi.web.Revision in project nifi by apache.

the class ControllerResource method updateRegistryClient.

/**
 * Updates the specified registry.
 *
 * @param httpServletRequest      request
 * @param id                      The id of the controller service to update.
 * @param requestRegistryEntity A controllerServiceEntity.
 * @return A controllerServiceEntity.
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/registry-clients/{id}")
@ApiOperation(value = "Updates a registry client", response = RegistryClientEntity.class, authorizations = { @Authorization(value = "Write - /controller") })
@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 updateRegistryClient(@Context HttpServletRequest httpServletRequest, @ApiParam(value = "The registry id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The registry configuration details.", required = true) final RegistryClientEntity requestRegistryEntity) {
    if (requestRegistryEntity == null || requestRegistryEntity.getComponent() == null) {
        throw new IllegalArgumentException("Registry details must be specified.");
    }
    if (requestRegistryEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }
    // ensure the ids are the same
    final RegistryDTO requestRegistryClient = requestRegistryEntity.getComponent();
    if (!id.equals(requestRegistryClient.getId())) {
        throw new IllegalArgumentException(String.format("The registry id (%s) in the request body does not equal the " + "registry id of the requested resource (%s).", requestRegistryClient.getId(), id));
    }
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT, requestRegistryEntity);
    }
    if (requestRegistryClient.getName() != null && StringUtils.isBlank(requestRegistryClient.getName())) {
        throw new IllegalArgumentException("Registry name must be specified.");
    }
    if (requestRegistryClient.getUri() != null && StringUtils.isBlank(requestRegistryClient.getUri())) {
        throw new IllegalArgumentException("Registry URL must be specified.");
    }
    // handle expects request (usually from the cluster manager)
    final Revision requestRevision = getRevision(requestRegistryEntity, id);
    return withWriteLock(serviceFacade, requestRegistryEntity, requestRevision, lookup -> {
        authorizeController(RequestAction.WRITE);
    }, null, (revision, registryEntity) -> {
        final RegistryDTO registry = registryEntity.getComponent();
        // update the controller service
        final RegistryClientEntity entity = serviceFacade.updateRegistryClient(revision, registry);
        populateRemainingRegistryEntityContent(entity);
        return generateOkResponse(entity).build();
    });
}
Also used : Revision(org.apache.nifi.web.Revision) RegistryClientEntity(org.apache.nifi.web.api.entity.RegistryClientEntity) RegistryDTO(org.apache.nifi.web.api.dto.RegistryDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 42 with Revision

use of org.apache.nifi.web.Revision in project nifi by apache.

the class ControllerServiceResource method updateControllerService.

/**
 * Updates the specified a new Controller Service.
 *
 * @param httpServletRequest      request
 * @param id                      The id of the controller service to update.
 * @param requestControllerServiceEntity A controllerServiceEntity.
 * @return A controllerServiceEntity.
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Updates a controller service", response = ControllerServiceEntity.class, authorizations = { @Authorization(value = "Write - /controller-services/{uuid}"), @Authorization(value = "Read - any referenced Controller Services if this request changes the reference - /controller-services/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response updateControllerService(@Context HttpServletRequest httpServletRequest, @ApiParam(value = "The controller service id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The controller service configuration details.", required = true) final ControllerServiceEntity requestControllerServiceEntity) {
    if (requestControllerServiceEntity == null || requestControllerServiceEntity.getComponent() == null) {
        throw new IllegalArgumentException("Controller service details must be specified.");
    }
    if (requestControllerServiceEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }
    // ensure the ids are the same
    final ControllerServiceDTO requestControllerServiceDTO = requestControllerServiceEntity.getComponent();
    if (!id.equals(requestControllerServiceDTO.getId())) {
        throw new IllegalArgumentException(String.format("The controller service id (%s) in the request body does not equal the " + "controller service id of the requested resource (%s).", requestControllerServiceDTO.getId(), id));
    }
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT, requestControllerServiceEntity);
    }
    // handle expects request (usually from the cluster manager)
    final Revision requestRevision = getRevision(requestControllerServiceEntity, id);
    return withWriteLock(serviceFacade, requestControllerServiceEntity, requestRevision, lookup -> {
        // authorize the service
        final ComponentAuthorizable authorizable = lookup.getControllerService(id);
        authorizable.getAuthorizable().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
        // authorize any referenced services
        AuthorizeControllerServiceReference.authorizeControllerServiceReferences(requestControllerServiceDTO.getProperties(), authorizable, authorizer, lookup);
    }, () -> serviceFacade.verifyUpdateControllerService(requestControllerServiceDTO), (revision, controllerServiceEntity) -> {
        final ControllerServiceDTO controllerService = controllerServiceEntity.getComponent();
        // update the controller service
        final ControllerServiceEntity entity = serviceFacade.updateControllerService(revision, controllerService);
        populateRemainingControllerServiceEntityContent(entity);
        return generateOkResponse(entity).build();
    });
}
Also used : ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) Revision(org.apache.nifi.web.Revision) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 43 with Revision

use of org.apache.nifi.web.Revision in project nifi by apache.

the class SnippetResource method deleteSnippet.

/**
 * Removes the specified snippet.
 *
 * @param httpServletRequest request
 * @param snippetId          The id of the snippet 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 the components in a snippet and discards the snippet", response = SnippetEntity.class, authorizations = { @Authorization(value = "Write - /{component-type}/{uuid} - For each component in the Snippet and their descendant components"), @Authorization(value = "Write - Parent Process Group - /process-groups/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response deleteSnippet(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The snippet id.", required = true) @PathParam("id") final String snippetId) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.DELETE);
    }
    final ComponentEntity requestEntity = new ComponentEntity();
    requestEntity.setId(snippetId);
    // get the revision from this snippet
    final Set<Revision> requestRevisions = serviceFacade.getRevisionsFromSnippet(snippetId);
    return withWriteLock(serviceFacade, requestEntity, requestRevisions, lookup -> {
        // ensure write permission to every component in the snippet excluding referenced services
        final SnippetAuthorizable snippet = lookup.getSnippet(snippetId);
        authorizeSnippet(snippet, authorizer, lookup, RequestAction.WRITE, true, false);
        // ensure write permission to the parent process group
        snippet.getParentProcessGroup().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, () -> serviceFacade.verifyDeleteSnippet(snippetId, requestRevisions.stream().map(rev -> rev.getComponentId()).collect(Collectors.toSet())), (revisions, entity) -> {
        // delete the specified snippet
        final SnippetEntity snippetEntity = serviceFacade.deleteSnippet(revisions, entity.getId());
        return generateOkResponse(snippetEntity).build();
    });
}
Also used : PathParam(javax.ws.rs.PathParam) Revision(org.apache.nifi.web.Revision) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) ApiResponses(io.swagger.annotations.ApiResponses) HttpMethod(javax.ws.rs.HttpMethod) ApiOperation(io.swagger.annotations.ApiOperation) SnippetEntity(org.apache.nifi.web.api.entity.SnippetEntity) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Api(io.swagger.annotations.Api) URI(java.net.URI) DELETE(javax.ws.rs.DELETE) NiFiServiceFacade(org.apache.nifi.web.NiFiServiceFacade) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) Authorizable(org.apache.nifi.authorization.resource.Authorizable) AuthorizableLookup(org.apache.nifi.authorization.AuthorizableLookup) RequestAction(org.apache.nifi.authorization.RequestAction) Set(java.util.Set) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) Authorizer(org.apache.nifi.authorization.Authorizer) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) NiFiUserUtils(org.apache.nifi.authorization.user.NiFiUserUtils) PUT(javax.ws.rs.PUT) SnippetDTO(org.apache.nifi.web.api.dto.SnippetDTO) Authorization(io.swagger.annotations.Authorization) Revision(org.apache.nifi.web.Revision) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) SnippetEntity(org.apache.nifi.web.api.entity.SnippetEntity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 44 with Revision

use of org.apache.nifi.web.Revision in project nifi by apache.

the class SnippetResource method updateSnippet.

/**
 * Move's the components in this Snippet into a new Process Group.
 *
 * @param httpServletRequest request
 * @param snippetId          The id of the snippet.
 * @param requestSnippetEntity      A snippetEntity
 * @return A snippetEntity
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Move's the components in this Snippet into a new Process Group and discards the snippet", response = SnippetEntity.class, authorizations = { @Authorization(value = "Write Process Group - /process-groups/{uuid}"), @Authorization(value = "Write - /{component-type}/{uuid} - For each component in the Snippet and their descendant components") })
@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 updateSnippet(@Context HttpServletRequest httpServletRequest, @ApiParam(value = "The snippet id.", required = true) @PathParam("id") String snippetId, @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.");
    }
    // ensure the ids are the same
    final SnippetDTO requestSnippetDTO = requestSnippetEntity.getSnippet();
    if (!snippetId.equals(requestSnippetDTO.getId())) {
        throw new IllegalArgumentException(String.format("The snippet id (%s) in the request body does not equal the " + "snippet id of the requested resource (%s).", requestSnippetDTO.getId(), snippetId));
    }
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT, requestSnippetEntity);
    }
    // get the revision from this snippet
    final Set<Revision> requestRevisions = serviceFacade.getRevisionsFromSnippet(snippetId);
    return withWriteLock(serviceFacade, requestSnippetEntity, requestRevisions, lookup -> {
        // ensure write access to the target process group
        if (requestSnippetDTO.getParentGroupId() != null) {
            lookup.getProcessGroup(requestSnippetDTO.getParentGroupId()).getAuthorizable().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
        }
        // ensure write permission to every component in the snippet excluding referenced services
        final SnippetAuthorizable snippet = lookup.getSnippet(snippetId);
        authorizeSnippet(snippet, authorizer, lookup, RequestAction.WRITE, false, false);
    }, () -> serviceFacade.verifyUpdateSnippet(requestSnippetDTO, requestRevisions.stream().map(rev -> rev.getComponentId()).collect(Collectors.toSet())), (revisions, snippetEntity) -> {
        // update the snippet
        final SnippetEntity entity = serviceFacade.updateSnippet(revisions, snippetEntity.getSnippet());
        populateRemainingSnippetEntityContent(entity);
        return generateOkResponse(entity).build();
    });
}
Also used : PathParam(javax.ws.rs.PathParam) Revision(org.apache.nifi.web.Revision) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) ApiResponses(io.swagger.annotations.ApiResponses) HttpMethod(javax.ws.rs.HttpMethod) ApiOperation(io.swagger.annotations.ApiOperation) SnippetEntity(org.apache.nifi.web.api.entity.SnippetEntity) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Api(io.swagger.annotations.Api) URI(java.net.URI) DELETE(javax.ws.rs.DELETE) NiFiServiceFacade(org.apache.nifi.web.NiFiServiceFacade) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) Authorizable(org.apache.nifi.authorization.resource.Authorizable) AuthorizableLookup(org.apache.nifi.authorization.AuthorizableLookup) RequestAction(org.apache.nifi.authorization.RequestAction) Set(java.util.Set) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) Authorizer(org.apache.nifi.authorization.Authorizer) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) NiFiUserUtils(org.apache.nifi.authorization.user.NiFiUserUtils) PUT(javax.ws.rs.PUT) SnippetDTO(org.apache.nifi.web.api.dto.SnippetDTO) Authorization(io.swagger.annotations.Authorization) SnippetDTO(org.apache.nifi.web.api.dto.SnippetDTO) Revision(org.apache.nifi.web.Revision) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) SnippetEntity(org.apache.nifi.web.api.entity.SnippetEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 45 with Revision

use of org.apache.nifi.web.Revision in project nifi by apache.

the class TenantsResource method updateUser.

/**
 * Updates a user.
 *
 * @param httpServletRequest request
 * @param id                 The id of the user to update.
 * @param requestUserEntity         An userEntity.
 * @return An userEntity.
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("users/{id}")
@ApiOperation(value = "Updates a user", notes = NON_GUARANTEED_ENDPOINT, response = UserEntity.class, authorizations = { @Authorization(value = "Write - /tenants") })
@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 updateUser(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The user id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The user configuration details.", required = true) final UserEntity requestUserEntity) {
    // ensure we're running with a configurable authorizer
    if (!AuthorizerCapabilityDetection.isConfigurableUserGroupProvider(authorizer)) {
        throw new IllegalStateException(AccessPolicyDAO.MSG_NON_CONFIGURABLE_USERS);
    }
    if (requestUserEntity == null || requestUserEntity.getComponent() == null) {
        throw new IllegalArgumentException("User details must be specified.");
    }
    if (requestUserEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }
    // ensure the ids are the same
    final UserDTO requestUserDTO = requestUserEntity.getComponent();
    if (!id.equals(requestUserDTO.getId())) {
        throw new IllegalArgumentException(String.format("The user id (%s) in the request body does not equal the " + "user id of the requested resource (%s).", requestUserDTO.getId(), id));
    }
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT, requestUserEntity);
    }
    // Extract the revision
    final Revision requestRevision = getRevision(requestUserEntity, id);
    return withWriteLock(serviceFacade, requestUserEntity, requestRevision, lookup -> {
        final Authorizable tenants = lookup.getTenant();
        tenants.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, null, (revision, userEntity) -> {
        // update the user
        final UserEntity entity = serviceFacade.updateUser(revision, userEntity.getComponent());
        populateRemainingUserEntityContent(entity);
        return generateOkResponse(entity).build();
    });
}
Also used : Revision(org.apache.nifi.web.Revision) UserDTO(org.apache.nifi.web.api.dto.UserDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) UserEntity(org.apache.nifi.web.api.entity.UserEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Revision (org.apache.nifi.web.Revision)73 ApiOperation (io.swagger.annotations.ApiOperation)61 ApiResponses (io.swagger.annotations.ApiResponses)61 Consumes (javax.ws.rs.Consumes)61 Produces (javax.ws.rs.Produces)61 Path (javax.ws.rs.Path)60 Authorizable (org.apache.nifi.authorization.resource.Authorizable)51 PUT (javax.ws.rs.PUT)30 ComponentAuthorizable (org.apache.nifi.authorization.ComponentAuthorizable)30 POST (javax.ws.rs.POST)25 DELETE (javax.ws.rs.DELETE)24 ProcessGroupAuthorizable (org.apache.nifi.authorization.ProcessGroupAuthorizable)21 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)21 PositionDTO (org.apache.nifi.web.api.dto.PositionDTO)19 SnippetAuthorizable (org.apache.nifi.authorization.SnippetAuthorizable)17 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)17 HashMap (java.util.HashMap)15 Map (java.util.Map)15 Set (java.util.Set)15 Collectors (java.util.stream.Collectors)15