Java Code Examples for org.apache.nifi.components.PropertyDescriptor#getDisplayName()

The following examples show how to use org.apache.nifi.components.PropertyDescriptor#getDisplayName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListedEntityTracker.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static void validateRequiredProperty(ValidationContext context, Collection<ValidationResult> results, PropertyDescriptor property) {
    if (!context.getProperty(property).isSet()) {
        final String displayName = property.getDisplayName();
        results.add(new ValidationResult.Builder()
                .subject(displayName)
                .explanation(format("'%s' is required to use '%s' listing strategy", displayName, AbstractListProcessor.BY_ENTITIES.getDisplayName()))
                .valid(false)
                .build());
    }
}
 
Example 2
Source File: AbstractComponentNode.java    From nifi with Apache License 2.0 4 votes vote down vote up
private ValidationResult validateControllerServiceApi(final PropertyDescriptor descriptor, final ControllerServiceNode controllerServiceNode) {
    final Class<? extends ControllerService> controllerServiceApiClass = descriptor.getControllerServiceDefinition();
    // If a processor accepts any service don't validate it.
    if (controllerServiceApiClass.equals(ControllerService.class)) {
        return null;
    }
    final ClassLoader controllerServiceApiClassLoader = controllerServiceApiClass.getClassLoader();
    final ExtensionManager extensionManager = serviceProvider.getExtensionManager();

    final String serviceId = controllerServiceNode.getIdentifier();
    final String propertyName = descriptor.getDisplayName();

    final Bundle controllerServiceApiBundle = extensionManager.getBundle(controllerServiceApiClassLoader);
    if (controllerServiceApiBundle == null) {
        return createInvalidResult(serviceId, propertyName, "Unable to find bundle for ControllerService API class " + controllerServiceApiClass.getCanonicalName());
    }
    final BundleCoordinate controllerServiceApiCoordinate = controllerServiceApiBundle.getBundleDetails().getCoordinate();

    final Bundle controllerServiceBundle = extensionManager.getBundle(controllerServiceNode.getBundleCoordinate());
    if (controllerServiceBundle == null) {
        return createInvalidResult(serviceId, propertyName, "Unable to find bundle for coordinate " + controllerServiceNode.getBundleCoordinate());
    }
    final BundleCoordinate controllerServiceCoordinate = controllerServiceBundle.getBundleDetails().getCoordinate();

    final boolean matchesApi = matchesApi(extensionManager, controllerServiceBundle, controllerServiceApiCoordinate);

    if (!matchesApi) {
        final String controllerServiceType = controllerServiceNode.getComponentType();
        final String controllerServiceApiType = controllerServiceApiClass.getSimpleName();

        final String explanation = new StringBuilder()
            .append(controllerServiceType).append(" - ").append(controllerServiceCoordinate.getVersion())
            .append(" from ").append(controllerServiceCoordinate.getGroup()).append(" - ").append(controllerServiceCoordinate.getId())
            .append(" is not compatible with ").append(controllerServiceApiType).append(" - ").append(controllerServiceApiCoordinate.getVersion())
            .append(" from ").append(controllerServiceApiCoordinate.getGroup()).append(" - ").append(controllerServiceApiCoordinate.getId())
            .toString();

        return createInvalidResult(serviceId, propertyName, explanation);
    }

    return null;
}
 
Example 3
Source File: AuthorizeControllerServiceReference.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * 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 ParameterParser parser = new ExpressionLanguageAgnosticParameterParser();
                        final ParameterTokenList tokenList = parser.parseTokens(proposedValue);
                        final boolean referencesParameter = !tokenList.toReferenceList().isEmpty();
                        if (referencesParameter) {
                            throw new IllegalArgumentException("The property '" + propertyDescriptor.getDisplayName() + "' cannot reference a Parameter because the property is a " +
                                "Controller Service reference. Allowing Controller Service references to make use of Parameters could result in security issues and a poor user experience. " +
                                "As a result, this is not allowed.");
                        }

                        final Authorizable newServiceAuthorizable = lookup.getControllerService(proposedValue).getAuthorizable();
                        newServiceAuthorizable.authorize(authorizer, RequestAction.READ, user);
                    }
                }
            }
        }
    }
}