Search in sources :

Example 31 with ResourceNotFoundException

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

the class StandardRemoteProcessGroupDAO method updateRemoteProcessGroupInputPort.

@Override
public RemoteGroupPort updateRemoteProcessGroupInputPort(String remoteProcessGroupId, RemoteProcessGroupPortDTO remoteProcessGroupPortDto) {
    final RemoteProcessGroup remoteProcessGroup = locateRemoteProcessGroup(remoteProcessGroupId);
    final RemoteGroupPort port = remoteProcessGroup.getInputPort(remoteProcessGroupPortDto.getId());
    if (port == null) {
        throw new ResourceNotFoundException(String.format("Unable to find remote process group input port with id '%s'.", remoteProcessGroupPortDto.getId()));
    }
    // verify the update
    verifyUpdatePort(port, remoteProcessGroupPortDto);
    // perform the update
    updatePort(port, remoteProcessGroupPortDto, remoteProcessGroup);
    remoteProcessGroup.getProcessGroup().onComponentModified();
    return port;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 32 with ResourceNotFoundException

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

the class StandardAuthorizableLookup method getAuthorizableFromResource.

@Override
public Authorizable getAuthorizableFromResource(String resource) {
    // parse the resource type
    ResourceType resourceType = null;
    for (ResourceType type : ResourceType.values()) {
        if (resource.equals(type.getValue()) || resource.startsWith(type.getValue() + "/")) {
            resourceType = type;
        }
    }
    if (resourceType == null) {
        throw new ResourceNotFoundException("Unrecognized resource: " + resource);
    }
    // if this is a policy or a provenance event resource, there should be another resource type
    if (ResourceType.Policy.equals(resourceType) || ResourceType.Data.equals(resourceType) || ResourceType.DataTransfer.equals(resourceType)) {
        final ResourceType primaryResourceType = resourceType;
        // get the resource type
        resource = StringUtils.substringAfter(resource, resourceType.getValue());
        for (ResourceType type : ResourceType.values()) {
            if (resource.equals(type.getValue()) || resource.startsWith(type.getValue() + "/")) {
                resourceType = type;
            }
        }
        if (resourceType == null) {
            throw new ResourceNotFoundException("Unrecognized resource: " + resource);
        }
        // must either be a policy, event, or data transfer
        if (ResourceType.Policy.equals(primaryResourceType)) {
            return new AccessPolicyAuthorizable(getAccessPolicy(resourceType, resource));
        } else if (ResourceType.Data.equals(primaryResourceType)) {
            return new DataAuthorizable(getAccessPolicy(resourceType, resource));
        } else {
            return new DataTransferAuthorizable(getAccessPolicy(resourceType, resource));
        }
    } else if (ResourceType.RestrictedComponents.equals(resourceType)) {
        final String slashRequiredPermission = StringUtils.substringAfter(resource, resourceType.getValue());
        if (slashRequiredPermission.startsWith("/")) {
            final RequiredPermission requiredPermission = RequiredPermission.valueOfPermissionIdentifier(slashRequiredPermission.substring(1));
            if (requiredPermission == null) {
                throw new ResourceNotFoundException("Unrecognized resource: " + resource);
            }
            return getRestrictedComponents(requiredPermission);
        } else {
            return getRestrictedComponents();
        }
    } else {
        return getAccessPolicy(resourceType, resource);
    }
}
Also used : RequiredPermission(org.apache.nifi.components.RequiredPermission) AccessPolicyAuthorizable(org.apache.nifi.authorization.resource.AccessPolicyAuthorizable) DataAuthorizable(org.apache.nifi.authorization.resource.DataAuthorizable) DataTransferAuthorizable(org.apache.nifi.authorization.resource.DataTransferAuthorizable) ResourceType(org.apache.nifi.authorization.resource.ResourceType) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 33 with ResourceNotFoundException

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

the class VolatileProvenanceRepository 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 34 with ResourceNotFoundException

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

the class StandardTemplateDAO method createTemplate.

@Override
public Template createTemplate(TemplateDTO templateDTO, String groupId) {
    final ProcessGroup processGroup = flowController.getGroup(groupId);
    if (processGroup == null) {
        throw new ResourceNotFoundException("Could not find Process Group with ID " + groupId);
    }
    verifyAdd(templateDTO.getName(), processGroup);
    TemplateUtils.scrubTemplate(templateDTO);
    final Template template = new Template(templateDTO);
    processGroup.addTemplate(template);
    return template;
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) Template(org.apache.nifi.controller.Template)

Example 35 with ResourceNotFoundException

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

the class DataAuthorizable method checkAuthorization.

@Override
public AuthorizationResult checkAuthorization(Authorizer authorizer, RequestAction action, NiFiUser user, Map<String, String> resourceContext) {
    if (user == null) {
        return AuthorizationResult.denied("Unknown user.");
    }
    AuthorizationResult result = null;
    // authorize each element in the chain
    NiFiUser chainedUser = user;
    do {
        try {
            // perform the current user authorization
            result = Authorizable.super.checkAuthorization(authorizer, action, chainedUser, resourceContext);
            // if authorization is not approved, reject
            if (!Result.Approved.equals(result.getResult())) {
                return result;
            }
            // go to the next user in the chain
            chainedUser = chainedUser.getChain();
        } catch (final ResourceNotFoundException e) {
            result = AuthorizationResult.denied("Unknown source component.");
        }
    } while (chainedUser != null);
    if (result == null) {
        result = AuthorizationResult.denied();
    }
    return result;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) AuthorizationResult(org.apache.nifi.authorization.AuthorizationResult) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

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