Search in sources :

Example 41 with ResourceNotFoundException

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

the class FlowController method createRemoteDataAuthorizable.

@Override
public Authorizable createRemoteDataAuthorizable(String remoteGroupPortId) {
    final DataAuthorizable authorizable;
    final RemoteGroupPort remoteGroupPort = getRootGroup().findRemoteGroupPort(remoteGroupPortId);
    if (remoteGroupPort == null) {
        throw new ResourceNotFoundException("The component that generated this event is no longer part of the data flow.");
    } else {
        // authorizable for remote group ports should be the remote process group
        authorizable = new DataAuthorizable(remoteGroupPort.getRemoteProcessGroup());
    }
    return authorizable;
}
Also used : RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) DataAuthorizable(org.apache.nifi.authorization.resource.DataAuthorizable) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 42 with ResourceNotFoundException

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

the class DataAuthorizable method authorize.

@Override
public void authorize(Authorizer authorizer, RequestAction action, NiFiUser user, Map<String, String> resourceContext) throws AccessDeniedException {
    if (user == null) {
        throw new AccessDeniedException("Unknown user.");
    }
    // authorize each element in the chain
    NiFiUser chainedUser = user;
    do {
        try {
            // perform the current user authorization
            Authorizable.super.authorize(authorizer, action, chainedUser, resourceContext);
            // go to the next user in the chain
            chainedUser = chainedUser.getChain();
        } catch (final ResourceNotFoundException e) {
            throw new AccessDeniedException("Unknown source component.");
        }
    } while (chainedUser != null);
}
Also used : AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 43 with ResourceNotFoundException

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

the class PersistentProvenanceRepository method isAuthorized.

public boolean isAuthorized(final ProvenanceEventRecord event, final NiFiUser user) {
    if (authorizer == null || user == null) {
        return true;
    }
    final Authorizable eventAuthorizable;
    try {
        if (event.isRemotePortType()) {
            eventAuthorizable = resourceFactory.createRemoteDataAuthorizable(event.getComponentId());
        } else {
            eventAuthorizable = resourceFactory.createLocalDataAuthorizable(event.getComponentId());
        }
    } catch (final ResourceNotFoundException rnfe) {
        return false;
    }
    final AuthorizationResult result = eventAuthorizable.checkAuthorization(authorizer, RequestAction.READ, user, event.getAttributes());
    return Result.Approved.equals(result.getResult());
}
Also used : Authorizable(org.apache.nifi.authorization.resource.Authorizable) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) AuthorizationResult(org.apache.nifi.authorization.AuthorizationResult)

Example 44 with ResourceNotFoundException

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

the class UserEventAuthorizer method isAuthorized.

@Override
public boolean isAuthorized(final ProvenanceEventRecord event) {
    if (authorizer == null || user == null) {
        return true;
    }
    final Authorizable eventAuthorizable;
    try {
        if (event.isRemotePortType()) {
            eventAuthorizable = resourceFactory.createRemoteDataAuthorizable(event.getComponentId());
        } else {
            eventAuthorizable = resourceFactory.createLocalDataAuthorizable(event.getComponentId());
        }
    } catch (final ResourceNotFoundException rnfe) {
        return false;
    }
    final AuthorizationResult result = eventAuthorizable.checkAuthorization(authorizer, RequestAction.READ, user, event.getAttributes());
    return Result.Approved.equals(result.getResult());
}
Also used : Authorizable(org.apache.nifi.authorization.resource.Authorizable) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) AuthorizationResult(org.apache.nifi.authorization.AuthorizationResult)

Example 45 with ResourceNotFoundException

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

the class VersionsResource method deleteRequest.

private Response deleteRequest(final String requestType, final String requestId) {
    if (requestId == null) {
        throw new IllegalArgumentException("Request ID must be specified.");
    }
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    // request manager will ensure that the current is the user that submitted this request
    final AsynchronousWebRequest<VersionControlInformationEntity> asyncRequest = requestManager.removeRequest(requestType, requestId, user);
    if (asyncRequest == null) {
        throw new ResourceNotFoundException("Could not find request of type " + requestType + " with ID " + requestId);
    }
    if (!asyncRequest.isComplete()) {
        asyncRequest.cancel();
    }
    final VersionedFlowUpdateRequestDTO updateRequestDto = new VersionedFlowUpdateRequestDTO();
    updateRequestDto.setComplete(asyncRequest.isComplete());
    updateRequestDto.setFailureReason(asyncRequest.getFailureReason());
    updateRequestDto.setLastUpdated(asyncRequest.getLastUpdated());
    updateRequestDto.setProcessGroupId(asyncRequest.getProcessGroupId());
    updateRequestDto.setRequestId(requestId);
    updateRequestDto.setUri(generateResourceUri("versions", requestType, requestId));
    updateRequestDto.setPercentCompleted(asyncRequest.getPercentComplete());
    updateRequestDto.setState(asyncRequest.getState());
    if (updateRequestDto.isComplete()) {
        final VersionControlInformationEntity vciEntity = serviceFacade.getVersionControlInformation(asyncRequest.getProcessGroupId());
        updateRequestDto.setVersionControlInformation(vciEntity == null ? null : vciEntity.getVersionControlInformation());
    }
    final RevisionDTO groupRevision = serviceFacade.getProcessGroup(asyncRequest.getProcessGroupId()).getRevision();
    final VersionedFlowUpdateRequestEntity updateRequestEntity = new VersionedFlowUpdateRequestEntity();
    updateRequestEntity.setProcessGroupRevision(groupRevision);
    updateRequestEntity.setRequest(updateRequestDto);
    return generateOkResponse(updateRequestEntity).build();
}
Also used : VersionControlInformationEntity(org.apache.nifi.web.api.entity.VersionControlInformationEntity) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) VersionedFlowUpdateRequestDTO(org.apache.nifi.web.api.dto.VersionedFlowUpdateRequestDTO) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) VersionedFlowUpdateRequestEntity(org.apache.nifi.web.api.entity.VersionedFlowUpdateRequestEntity)

Aggregations

ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)59 ProcessGroup (org.apache.nifi.groups.ProcessGroup)22 Authorizable (org.apache.nifi.authorization.resource.Authorizable)16 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)16 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)12 Connection (org.apache.nifi.connectable.Connection)10 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)10 IOException (java.io.IOException)9 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)7 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 Consumes (javax.ws.rs.Consumes)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 AuthorizationResult (org.apache.nifi.authorization.AuthorizationResult)5 DataAuthorizable (org.apache.nifi.authorization.resource.DataAuthorizable)5 FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)5 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)5 RemoteProcessGroupStatus (org.apache.nifi.controller.status.RemoteProcessGroupStatus)5 HashMap (java.util.HashMap)4