Search in sources :

Example 36 with ResourceNotFoundException

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

the class FlowController method createLocalDataAuthorizable.

@Override
public Authorizable createLocalDataAuthorizable(final String componentId) {
    final String rootGroupId = getRootGroupId();
    // Provenance Events are generated only by connectable components, with the exception of DOWNLOAD events,
    // which have the root process group's identifier assigned as the component ID, and DROP events, which
    // could have the connection identifier assigned as the component ID. So, we check if the component ID
    // is set to the root group and otherwise assume that the ID is that of a connectable or connection.
    final DataAuthorizable authorizable;
    if (rootGroupId.equals(componentId)) {
        authorizable = new DataAuthorizable(getRootGroup());
    } else {
        // check if the component is a connectable, this should be the case most often
        final Connectable connectable = getRootGroup().findLocalConnectable(componentId);
        if (connectable == null) {
            // if the component id is not a connectable then consider a connection
            final Connection connection = getRootGroup().findConnection(componentId);
            if (connection == null) {
                throw new ResourceNotFoundException("The component that generated this event is no longer part of the data flow.");
            } else {
                // authorizable for connection data is associated with the source connectable
                authorizable = new DataAuthorizable(connection.getSource());
            }
        } else {
            authorizable = new DataAuthorizable(connectable);
        }
    }
    return authorizable;
}
Also used : Connectable(org.apache.nifi.connectable.Connectable) DataAuthorizable(org.apache.nifi.authorization.resource.DataAuthorizable) Connection(org.apache.nifi.connectable.Connection) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) StandardConnection(org.apache.nifi.connectable.StandardConnection) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 37 with ResourceNotFoundException

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

the class MiNiFiPersistentProvenanceRepository 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 38 with ResourceNotFoundException

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

the class AuthorizeControllerServiceReference method authorizeControllerServiceReferences.

/**
 * Authorizes the proposed properties for the specified authorizable.
 *
 * @param proposedProperties proposed properties
 * @param authorizable authorizable that may reference a controller service
 * @param authorizer authorizer
 * @param lookup lookup
 */
public static void authorizeControllerServiceReferences(final Map<String, String> proposedProperties, final ComponentAuthorizable authorizable, final Authorizer authorizer, final AuthorizableLookup lookup) {
    // only attempt to authorize if properties are changing
    if (proposedProperties != null) {
        final NiFiUser user = NiFiUserUtils.getNiFiUser();
        for (final Map.Entry<String, String> entry : proposedProperties.entrySet()) {
            final String propertyName = entry.getKey();
            final PropertyDescriptor propertyDescriptor = authorizable.getPropertyDescriptor(propertyName);
            // if this descriptor identifies a controller service
            if (propertyDescriptor.getControllerServiceDefinition() != null) {
                final String currentValue = authorizable.getValue(propertyDescriptor);
                final String proposedValue = entry.getValue();
                // if the value is changing
                if (!Objects.equals(currentValue, proposedValue)) {
                    // ensure access to the old service
                    if (currentValue != null) {
                        try {
                            final Authorizable currentServiceAuthorizable = lookup.getControllerService(currentValue).getAuthorizable();
                            currentServiceAuthorizable.authorize(authorizer, RequestAction.READ, user);
                        } catch (ResourceNotFoundException e) {
                        // ignore if the resource is not found, if currentValue was previously deleted, it should not stop assignment of proposedValue
                        }
                    }
                    // ensure access to the new service
                    if (proposedValue != null) {
                        final Authorizable newServiceAuthorizable = lookup.getControllerService(proposedValue).getAuthorizable();
                        newServiceAuthorizable.authorize(authorizer, RequestAction.READ, user);
                    }
                }
            }
        }
    }
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) Map(java.util.Map)

Example 39 with ResourceNotFoundException

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

the class StandardAuthorizableLookup method getControllerServiceReferencingComponent.

@Override
public Authorizable getControllerServiceReferencingComponent(String controllerServiceId, String id) {
    final ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceId);
    final ControllerServiceReference referencingComponents = controllerService.getReferences();
    final ConfiguredComponent reference = findControllerServiceReferencingComponent(referencingComponents, id);
    if (reference == null) {
        throw new ResourceNotFoundException("Unable to find referencing component with id " + id);
    }
    return reference;
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ControllerServiceReference(org.apache.nifi.controller.service.ControllerServiceReference) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 40 with ResourceNotFoundException

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

the class StandardAuthorizableLookup method getLocalConnectable.

@Override
public Authorizable getLocalConnectable(String id) {
    final ProcessGroup group = processGroupDAO.getProcessGroup(controllerFacade.getRootGroupId());
    final Connectable connectable = group.findLocalConnectable(id);
    if (connectable == null) {
        throw new ResourceNotFoundException("Unable to find component with id " + id);
    }
    return connectable;
}
Also used : Connectable(org.apache.nifi.connectable.Connectable) ProcessGroup(org.apache.nifi.groups.ProcessGroup) 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