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

The following examples show how to use org.apache.nifi.components.PropertyDescriptor#isSensitive() . 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: StandardSnippetDAO.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void lookupSensitiveControllerServiceProperties(final Set<ControllerServiceDTO> controllerServices) {
    // go through each service
    for (final ControllerServiceDTO serviceDTO : controllerServices) {

        // ensure that some property configuration have been specified
        final Map<String, String> serviceProperties = serviceDTO.getProperties();
        if (serviceProperties != null) {
            // find the corresponding controller service
            final ControllerServiceNode serviceNode = flowController.getControllerServiceNode(serviceDTO.getId());
            if (serviceNode == null) {
                throw new IllegalArgumentException(String.format("Unable to create snippet because Controller Service '%s' could not be found", serviceDTO.getId()));
            }

            // look for sensitive properties get the actual value
            for (Entry<PropertyDescriptor, String> entry : serviceNode.getProperties().entrySet()) {
                final PropertyDescriptor descriptor = entry.getKey();

                if (descriptor.isSensitive()) {
                    serviceProperties.put(descriptor.getName(), entry.getValue());
                }
            }
        }
    }
}
 
Example 2
Source File: StandardTemplateDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void verifyParameterReference(final PropertyDescriptor descriptor, final ParameterTokenList parameterTokenList, final ParameterContext parameterContext) {
    if (descriptor == null || parameterTokenList == null) {
        return;
    }

    final List<ParameterReference> references = parameterTokenList.toReferenceList();
    for (final ParameterReference reference : references) {
        final String parameterName = reference.getParameterName();
        final Optional<Parameter> parameter = parameterContext.getParameter(parameterName);
        if (!parameter.isPresent()) {
            continue;
        }

        final boolean parameterSensitive = parameter.get().getDescriptor().isSensitive();
        if (descriptor.isSensitive() && !parameterSensitive) {
            throw new IllegalStateException("Cannot instantiate template within this Process Group because template references the '" + parameterName
                + "' Parameter in a sensitive property, but the Parameter is not sensitive");
        }
        if (!descriptor.isSensitive() && parameterSensitive) {
            throw new IllegalStateException("Cannot instantiate template within this Process Group because template references the '" + parameterName
                + "' Parameter in a non-sensitive property, but the Parameter is sensitive");
        }
    }
}
 
Example 3
Source File: StandardSnippetDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void lookupSensitiveControllerServiceProperties(final Set<ControllerServiceDTO> controllerServices) {
    // go through each service
    for (final ControllerServiceDTO serviceDTO : controllerServices) {

        // ensure that some property configuration have been specified
        final Map<String, String> serviceProperties = serviceDTO.getProperties();
        if (serviceProperties != null) {
            // find the corresponding controller service
            final ControllerServiceNode serviceNode = flowController.getFlowManager().getControllerServiceNode(serviceDTO.getId());
            if (serviceNode == null) {
                throw new IllegalArgumentException(String.format("Unable to create snippet because Controller Service '%s' could not be found", serviceDTO.getId()));
            }

            // look for sensitive properties get the actual value
            for (Entry<PropertyDescriptor, String> entry : serviceNode.getRawPropertyValues().entrySet()) {
                final PropertyDescriptor descriptor = entry.getKey();

                if (descriptor.isSensitive()) {
                    serviceProperties.put(descriptor.getName(), entry.getValue());
                }
            }
        }
    }
}
 
Example 4
Source File: PropertyMatcher.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void match(final ComponentNode component, final SearchQuery query, final List<String> matches) {
    final String searchTerm = query.getTerm();

    if (!propertiesAreFilteredOut(query)) {
        for (final Map.Entry<PropertyDescriptor, String> entry : component.getRawPropertyValues().entrySet()) {
            final PropertyDescriptor descriptor = entry.getKey();
            addIfMatching(searchTerm, descriptor.getName(), LABEL_NAME, matches);
            addIfMatching(searchTerm, descriptor.getDescription(), LABEL_DESCRIPTION, matches);

            // never include sensitive properties values in search results
            if (!descriptor.isSensitive()) {
                final String value = Optional.ofNullable(entry.getValue()).orElse(descriptor.getDefaultValue());

                // evaluate if the value matches the search criteria
                if (StringUtils.containsIgnoreCase(value, searchTerm)) {
                    matches.add(LABEL_VALUE + SEPARATOR + descriptor.getName() + " - " + value);
                }
            }
        }
    }
}
 
Example 5
Source File: StandardParameterContext.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void validateParameterSensitivity(final Parameter parameter, final ComponentNode componentNode) {
    final String paramName = parameter.getDescriptor().getName();

    for (final Map.Entry<PropertyDescriptor, PropertyConfiguration> entry :  componentNode.getProperties().entrySet()) {
        final PropertyConfiguration configuration = entry.getValue();
        if (configuration == null) {
            continue;
        }

        for (final ParameterReference reference : configuration.getParameterReferences()) {
            if (parameter.getDescriptor().getName().equals(reference.getParameterName())) {
                final PropertyDescriptor propertyDescriptor = entry.getKey();
                if (propertyDescriptor.isSensitive() && !parameter.getDescriptor().isSensitive()) {
                    throw new IllegalStateException("Cannot add Parameter with name '" + paramName + "' unless that Parameter is Sensitive because a Parameter with that name is already " +
                        "referenced from a Sensitive Property");
                }

                if (!propertyDescriptor.isSensitive() && parameter.getDescriptor().isSensitive()) {
                    throw new IllegalStateException("Cannot add Parameter with name '" + paramName + "' unless that Parameter is Not Sensitive because a Parameter with that name is already " +
                        "referenced from a Property that is not Sensitive");
                }
            }
        }
    }
}
 
Example 6
Source File: HtmlDocumentationWriter.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Indicates whether or not the component contains at least one sensitive property.
 *
 * @param component the component to interogate
 * @return whether or not the component contains at least one sensitive property.
 */
private boolean containsSensitiveProperties(final ConfigurableComponent component) {
    for (PropertyDescriptor descriptor : component.getPropertyDescriptors()) {
        if (descriptor.isSensitive()) {
            return true;
        }
    }
    return false;
}
 
Example 7
Source File: StandardSnippetDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void lookupSensitiveProcessorProperties(final Set<ProcessorDTO> processors) {
    final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());

    // go through each processor
    for (final ProcessorDTO processorDTO : processors) {
        final ProcessorConfigDTO processorConfig = processorDTO.getConfig();

        // ensure that some property configuration have been specified
        if (processorConfig != null && processorConfig.getProperties() != null) {
            final Map<String, String> processorProperties = processorConfig.getProperties();

            // find the corresponding processor
            final ProcessorNode processorNode = rootGroup.findProcessor(processorDTO.getId());
            if (processorNode == null) {
                throw new IllegalArgumentException(String.format("Unable to create snippet because Processor '%s' could not be found", processorDTO.getId()));
            }

            // look for sensitive properties get the actual value
            for (Entry<PropertyDescriptor, String> entry : processorNode.getProperties().entrySet()) {
                final PropertyDescriptor descriptor = entry.getKey();

                if (descriptor.isSensitive()) {
                    processorProperties.put(descriptor.getName(), entry.getValue());
                }
            }
        }
    }
}
 
Example 8
Source File: StandardFlowSerializer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private static void addConfiguration(final Element element, final Map<PropertyDescriptor, String> properties, final String annotationData, final StringEncryptor encryptor) {
    final Document doc = element.getOwnerDocument();
    for (final Map.Entry<PropertyDescriptor, String> entry : properties.entrySet()) {
        final PropertyDescriptor descriptor = entry.getKey();
        String value = entry.getValue();

        if (value != null && descriptor.isSensitive()) {
            value = ENC_PREFIX + encryptor.encrypt(value) + ENC_SUFFIX;
        }

        if (value == null) {
            value = descriptor.getDefaultValue();
        }

        final Element propElement = doc.createElement("property");
        addTextElement(propElement, "name", descriptor.getName());
        if (value != null) {
            addTextElement(propElement, "value", value);
        }

        element.appendChild(propElement);
    }

    if (annotationData != null) {
        addTextElement(element, "annotationData", annotationData);
    }
}
 
Example 9
Source File: HtmlDocumentationWriter.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Indicates whether or not the component contains at least one sensitive property.
 *
 * @param component the component to interogate
 * @return whether or not the component contains at least one sensitive property.
 */
private boolean containsSensitiveProperties(final ConfigurableComponent component) {
    for (PropertyDescriptor descriptor : component.getPropertyDescriptors()) {
        if (descriptor.isSensitive()) {
            return true;
        }
    }
    return false;
}
 
Example 10
Source File: StandardSnippetDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void lookupSensitiveProcessorProperties(final Set<ProcessorDTO> processors) {
    final ProcessGroup rootGroup = flowController.getFlowManager().getRootGroup();

    // go through each processor
    for (final ProcessorDTO processorDTO : processors) {
        final ProcessorConfigDTO processorConfig = processorDTO.getConfig();

        // ensure that some property configuration have been specified
        if (processorConfig != null && processorConfig.getProperties() != null) {
            final Map<String, String> processorProperties = processorConfig.getProperties();

            // find the corresponding processor
            final ProcessorNode processorNode = rootGroup.findProcessor(processorDTO.getId());
            if (processorNode == null) {
                throw new IllegalArgumentException(String.format("Unable to create snippet because Processor '%s' could not be found", processorDTO.getId()));
            }

            // look for sensitive properties get the actual value
            for (Entry<PropertyDescriptor, String> entry : processorNode.getRawPropertyValues().entrySet()) {
                final PropertyDescriptor descriptor = entry.getKey();

                if (descriptor.isSensitive()) {
                    processorProperties.put(descriptor.getName(), entry.getValue());
                }
            }
        }
    }
}
 
Example 11
Source File: StandardFlowSerializer.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static void addConfiguration(final Element element, final Map<PropertyDescriptor, String> properties, final String annotationData, final StringEncryptor encryptor) {
    final Document doc = element.getOwnerDocument();
    for (final Map.Entry<PropertyDescriptor, String> entry : properties.entrySet()) {
        final PropertyDescriptor descriptor = entry.getKey();
        String value = entry.getValue();

        if (value == null) {
            value = descriptor.getDefaultValue();
        }

        if (value != null && descriptor.isSensitive()) {
            value = ENC_PREFIX + encryptor.encrypt(value) + ENC_SUFFIX;
        }

        final Element propElement = doc.createElement("property");
        addTextElement(propElement, "name", descriptor.getName());
        if (value != null) {
            addTextElement(propElement, "value", value);
        }

        element.appendChild(propElement);
    }

    if (annotationData != null) {
        addTextElement(element, "annotationData", annotationData);
    }
}
 
Example 12
Source File: NiFiRegistryFlowMapper.java    From nifi with Apache License 2.0 5 votes vote down vote up
private boolean isMappable(final PropertyDescriptor propertyDescriptor, final PropertyConfiguration propertyConfiguration) {
    if (!propertyDescriptor.isSensitive()) { // If the property is not sensitive, it can be mapped.
        return true;
    }

    if (propertyConfiguration == null) {
        return false;
    }

    // Sensitive properties can be mapped if and only if they reference a Parameter. If a sensitive property references a parameter, it cannot contain any other value around it.
    // For example, for a non-sensitive property, a value of "hello#{param}123" is valid, but for a sensitive property, it is invalid. Only something like "hello123" or "#{param}" is valid.
    // Thus, we will map sensitive properties only if they reference a parameter.
    return !propertyConfiguration.getParameterReferences().isEmpty();
}
 
Example 13
Source File: HtmlDocumentationWriter.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Writes the PropertyDescriptors out as a table.
 *
 * @param configurableComponent the component to describe
 * @param xmlStreamWriter the stream writer
 * @throws XMLStreamException thrown if there was a problem writing to the
 * XML Stream
 */
protected void writeProperties(final ConfigurableComponent configurableComponent,
        final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {

    final List<PropertyDescriptor> properties = configurableComponent.getPropertyDescriptors();
    writeSimpleElement(xmlStreamWriter, "h3", "Properties: ");

    if (properties.size() > 0) {
        final boolean containsExpressionLanguage = containsExpressionLanguage(configurableComponent);
        final boolean containsSensitiveProperties = containsSensitiveProperties(configurableComponent);
        xmlStreamWriter.writeStartElement("p");
        xmlStreamWriter.writeCharacters("In the list below, the names of required properties appear in ");
        writeSimpleElement(xmlStreamWriter, "strong", "bold");
        xmlStreamWriter.writeCharacters(". Any other properties (not in bold) are considered optional. " +
                "The table also indicates any default values");
        if (containsExpressionLanguage) {
            if (!containsSensitiveProperties) {
                xmlStreamWriter.writeCharacters(", and ");
            } else {
                xmlStreamWriter.writeCharacters(", ");
            }
            xmlStreamWriter.writeCharacters("whether a property supports the ");
            writeLink(xmlStreamWriter, "NiFi Expression Language", "../../html/expression-language-guide.html");
        }
        if (containsSensitiveProperties) {
            xmlStreamWriter.writeCharacters(", and whether a property is considered " + "\"sensitive\", meaning that its value will be encrypted. Before entering a "
                    + "value in a sensitive property, ensure that the ");

            writeSimpleElement(xmlStreamWriter, "strong", "nifi.properties");
            xmlStreamWriter.writeCharacters(" file has " + "an entry for the property ");
            writeSimpleElement(xmlStreamWriter, "strong", "nifi.sensitive.props.key");
        }
        xmlStreamWriter.writeCharacters(".");
        xmlStreamWriter.writeEndElement();

        xmlStreamWriter.writeStartElement("table");
        xmlStreamWriter.writeAttribute("id", "properties");

        // write the header row
        xmlStreamWriter.writeStartElement("tr");
        writeSimpleElement(xmlStreamWriter, "th", "Name");
        writeSimpleElement(xmlStreamWriter, "th", "Default Value");
        writeSimpleElement(xmlStreamWriter, "th", "Allowable Values");
        writeSimpleElement(xmlStreamWriter, "th", "Description");
        xmlStreamWriter.writeEndElement();

        // write the individual properties
        for (PropertyDescriptor property : properties) {
            xmlStreamWriter.writeStartElement("tr");
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeAttribute("id", "name");
            if (property.isRequired()) {
                writeSimpleElement(xmlStreamWriter, "strong", property.getDisplayName());
            } else {
                xmlStreamWriter.writeCharacters(property.getDisplayName());
            }

            xmlStreamWriter.writeEndElement();
            writeSimpleElement(xmlStreamWriter, "td", property.getDefaultValue(), false, "default-value");
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeAttribute("id", "allowable-values");
            writeValidValues(xmlStreamWriter, property);
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeStartElement("td");
            xmlStreamWriter.writeAttribute("id", "description");
            if (property.getDescription() != null && property.getDescription().trim().length() > 0) {
                xmlStreamWriter.writeCharacters(property.getDescription());
            } else {
                xmlStreamWriter.writeCharacters("No Description Provided.");
            }

            if (property.isSensitive()) {
                xmlStreamWriter.writeEmptyElement("br");
                writeSimpleElement(xmlStreamWriter, "strong", "Sensitive Property: true");
            }

            if (property.isExpressionLanguageSupported()) {
                xmlStreamWriter.writeEmptyElement("br");
                writeSimpleElement(xmlStreamWriter, "strong", "Supports Expression Language: true");
            }
            xmlStreamWriter.writeEndElement();

            xmlStreamWriter.writeEndElement();
        }

        // TODO support dynamic properties...
        xmlStreamWriter.writeEndElement();

    } else {
        writeSimpleElement(xmlStreamWriter, "p", "This component has no required or optional properties.");
    }
}
 
Example 14
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private ComponentSearchResultDTO search(final String searchStr, final ProcessorNode procNode) {
    final List<String> matches = new ArrayList<>();
    final Processor processor = procNode.getProcessor();

    addIfAppropriate(searchStr, procNode.getIdentifier(), "Id", matches);
    addIfAppropriate(searchStr, procNode.getName(), "Name", matches);
    addIfAppropriate(searchStr, procNode.getComments(), "Comments", matches);

    // consider scheduling strategy
    if (SchedulingStrategy.EVENT_DRIVEN.equals(procNode.getSchedulingStrategy()) && StringUtils.containsIgnoreCase("event", searchStr)) {
        matches.add("Scheduling strategy: Event driven");
    } else if (SchedulingStrategy.TIMER_DRIVEN.equals(procNode.getSchedulingStrategy()) && StringUtils.containsIgnoreCase("timer", searchStr)) {
        matches.add("Scheduling strategy: Timer driven");
    } else if (SchedulingStrategy.PRIMARY_NODE_ONLY.equals(procNode.getSchedulingStrategy()) && StringUtils.containsIgnoreCase("primary", searchStr)) {
        // PRIMARY_NODE_ONLY has been deprecated as a SchedulingStrategy and replaced by PRIMARY as an ExecutionNode.
        matches.add("Scheduling strategy: On primary node");
    }

    // consider execution node
    if (ExecutionNode.PRIMARY.equals(procNode.getExecutionNode()) && StringUtils.containsIgnoreCase("primary", searchStr)) {
        matches.add("Execution node: primary");
    }

    // consider scheduled state
    if (ScheduledState.DISABLED.equals(procNode.getScheduledState())) {
        if (StringUtils.containsIgnoreCase("disabled", searchStr)) {
            matches.add("Run status: Disabled");
        }
    } else {
        if (StringUtils.containsIgnoreCase("invalid", searchStr) && !procNode.isValid()) {
            matches.add("Run status: Invalid");
        } else if (ScheduledState.RUNNING.equals(procNode.getScheduledState()) && StringUtils.containsIgnoreCase("running", searchStr)) {
            matches.add("Run status: Running");
        } else if (ScheduledState.STOPPED.equals(procNode.getScheduledState()) && StringUtils.containsIgnoreCase("stopped", searchStr)) {
            matches.add("Run status: Stopped");
        }
    }

    for (final Relationship relationship : procNode.getRelationships()) {
        addIfAppropriate(searchStr, relationship.getName(), "Relationship", matches);
    }

    // Add both the actual class name and the component type. This allows us to search for 'Ghost'
    // to search for components that could not be instantiated.
    addIfAppropriate(searchStr, processor.getClass().getSimpleName(), "Type", matches);
    addIfAppropriate(searchStr, procNode.getComponentType(), "Type", matches);

    for (final Map.Entry<PropertyDescriptor, String> entry : procNode.getProperties().entrySet()) {
        final PropertyDescriptor descriptor = entry.getKey();

        addIfAppropriate(searchStr, descriptor.getName(), "Property name", matches);
        addIfAppropriate(searchStr, descriptor.getDescription(), "Property description", matches);

        // never include sensitive properties values in search results
        if (descriptor.isSensitive()) {
            continue;
        }

        String value = entry.getValue();

        // if unset consider default value
        if (value == null) {
            value = descriptor.getDefaultValue();
        }

        // evaluate if the value matches the search criteria
        if (StringUtils.containsIgnoreCase(value, searchStr)) {
            matches.add("Property value: " + descriptor.getName() + " - " + value);
        }
    }

    // consider searching the processor directly
    if (processor instanceof Searchable) {
        final Searchable searchable = (Searchable) processor;

        final SearchContext context = new StandardSearchContext(searchStr, procNode, flowController, variableRegistry);

        // search the processor using the appropriate thread context classloader
        try (final NarCloseable x = NarCloseable.withComponentNarLoader(processor.getClass(), processor.getIdentifier())) {
            final Collection<SearchResult> searchResults = searchable.search(context);
            if (CollectionUtils.isNotEmpty(searchResults)) {
                for (final SearchResult searchResult : searchResults) {
                    matches.add(searchResult.getLabel() + ": " + searchResult.getMatch());
                }
            }
        } catch (final Throwable t) {
            // log this as error
        }
    }

    if (matches.isEmpty()) {
        return null;
    }

    final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
    result.setId(procNode.getIdentifier());
    result.setMatches(matches);
    result.setName(procNode.getName());
    return result;
}
 
Example 15
Source File: StatelessProcessContext.java    From nifi with Apache License 2.0 4 votes vote down vote up
private List<ValidationResult> validateParameterReferences() {
    final List<ValidationResult> results = new ArrayList<>();

    for (final Map.Entry<PropertyDescriptor, PropertyConfiguration> entry : properties.entrySet()) {
        final PropertyDescriptor propertyDescriptor = entry.getKey();
        final PropertyConfiguration configuration = entry.getValue();
        final List<ParameterReference> references = configuration.getParameterReferences();

        for (final ParameterReference reference : references) {
            final String parameterName = reference.getParameterName();

            final Optional<Parameter> parameter = parameterContext.getParameter(parameterName);
            if (!parameter.isPresent()) {
                results.add(new ValidationResult.Builder()
                    .subject(propertyDescriptor.getDisplayName())
                    .valid(false)
                    .explanation("Property References Parameter '" + parameterName + "' but that Parameter is not defined in the Stateless Flow configuration")
                    .build());
                continue;
            }

            final boolean parameterSensitive = parameter.get().getDescriptor().isSensitive();

            if (parameterSensitive && !propertyDescriptor.isSensitive()) {
                results.add(new ValidationResult.Builder()
                    .subject(propertyDescriptor.getDisplayName())
                    .valid(false)
                    .explanation("Property References Parameter '" + parameterName + "', which is a Sensitive Parameter, but the Property is not a Sensitive Property. Sensitive Parameters " +
                        "may only be referenced by Sensitive Properties.")
                    .build());
                continue;
            }

            if (!parameterSensitive && propertyDescriptor.isSensitive()) {
                results.add(new ValidationResult.Builder()
                    .subject(propertyDescriptor.getDisplayName())
                    .valid(false)
                    .explanation("Property References Parameter '" + parameterName + "', which is not a Sensitive Parameter, but the Property is a Sensitive Property. Sensitive Properties " +
                        "may only reference Sensitive Parameters.")
                    .build());
                continue;
            }
        }
    }

    return results;
}