Search in sources :

Example 1 with ComponentType

use of org.apache.nifi.reporting.ComponentType in project nifi by apache.

the class StandardNiFiServiceFacade method authorizeBulletin.

private boolean authorizeBulletin(final Bulletin bulletin) {
    final String sourceId = bulletin.getSourceId();
    final ComponentType type = bulletin.getSourceType();
    final Authorizable authorizable;
    try {
        switch(type) {
            case PROCESSOR:
                authorizable = authorizableLookup.getProcessor(sourceId).getAuthorizable();
                break;
            case REPORTING_TASK:
                authorizable = authorizableLookup.getReportingTask(sourceId).getAuthorizable();
                break;
            case CONTROLLER_SERVICE:
                authorizable = authorizableLookup.getControllerService(sourceId).getAuthorizable();
                break;
            case FLOW_CONTROLLER:
                authorizable = controllerFacade;
                break;
            case INPUT_PORT:
                authorizable = authorizableLookup.getInputPort(sourceId);
                break;
            case OUTPUT_PORT:
                authorizable = authorizableLookup.getOutputPort(sourceId);
                break;
            case REMOTE_PROCESS_GROUP:
                authorizable = authorizableLookup.getRemoteProcessGroup(sourceId);
                break;
            default:
                throw new WebApplicationException(Response.serverError().entity("An unexpected type of component is the source of this bulletin.").build());
        }
    } catch (final ResourceNotFoundException e) {
        // if the underlying component is gone, disallow
        return false;
    }
    // perform the authorization
    final AuthorizationResult result = authorizable.checkAuthorization(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    return Result.Approved.equals(result.getResult());
}
Also used : ComponentType(org.apache.nifi.reporting.ComponentType) WebApplicationException(javax.ws.rs.WebApplicationException) Authorizable(org.apache.nifi.authorization.resource.Authorizable) AuthorizationResult(org.apache.nifi.authorization.AuthorizationResult)

Example 2 with ComponentType

use of org.apache.nifi.reporting.ComponentType in project nifi by apache.

the class BulletinFactory method createBulletin.

public static Bulletin createBulletin(final Connectable connectable, final String category, final String severity, final String message) {
    final ComponentType type;
    switch(connectable.getConnectableType()) {
        case REMOTE_INPUT_PORT:
        case REMOTE_OUTPUT_PORT:
            type = ComponentType.REMOTE_PROCESS_GROUP;
            break;
        case INPUT_PORT:
            type = ComponentType.INPUT_PORT;
            break;
        case OUTPUT_PORT:
            type = ComponentType.OUTPUT_PORT;
            break;
        case PROCESSOR:
        default:
            type = ComponentType.PROCESSOR;
            break;
    }
    final ProcessGroup group = connectable.getProcessGroup();
    final String groupId = group == null ? null : group.getIdentifier();
    final String groupName = group == null ? null : group.getName();
    return BulletinFactory.createBulletin(groupId, groupName, connectable.getIdentifier(), type, connectable.getName(), category, severity, message);
}
Also used : ComponentType(org.apache.nifi.reporting.ComponentType) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Aggregations

ComponentType (org.apache.nifi.reporting.ComponentType)2 WebApplicationException (javax.ws.rs.WebApplicationException)1 AuthorizationResult (org.apache.nifi.authorization.AuthorizationResult)1 Authorizable (org.apache.nifi.authorization.resource.Authorizable)1 ProcessGroup (org.apache.nifi.groups.ProcessGroup)1