This is an automated email from the ASF dual-hosted git repository.
mcgilman pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new ba68915e4b6 NIFI-16616 Resolve Parameters when evaluating Search
Context properties (#11955)
ba68915e4b6 is described below
commit ba68915e4b67916952e206d5a1661c6f608561b5
Author: Joe Witt <[email protected]>
AuthorDate: Mon Nov 30 14:20:20 2026 -0700
NIFI-16616 Resolve Parameters when evaluating Search Context properties
(#11955)
* NIFI-16616 Use effective property values in StandardSearchContext
Co-authored-by: Cursor <[email protected]>
* NIFI-16616 Preserve raw Search Context values and resolve matching
Parameters on evaluation
Co-authored-by: Cursor <[email protected]>
* NIFI-16616 Clarify SensitivityMatchingParameterLookup Javadoc and assert
exact values in tests
Co-authored-by: Cursor <[email protected]>
---------
Co-authored-by: Cursor <[email protected]>
---
.../nifi/web/controller/StandardSearchContext.java | 34 ++++-
.../web/controller/TestStandardSearchContext.java | 140 +++++++++++++++++++++
2 files changed, 173 insertions(+), 1 deletion(-)
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/StandardSearchContext.java
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/StandardSearchContext.java
index e1981836d08..cefa301dc86 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/StandardSearchContext.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/StandardSearchContext.java
@@ -24,10 +24,12 @@ import
org.apache.nifi.components.resource.StandardResourceContext;
import org.apache.nifi.components.resource.StandardResourceReferenceFactory;
import org.apache.nifi.controller.ControllerServiceLookup;
import org.apache.nifi.controller.ProcessorNode;
+import org.apache.nifi.parameter.Parameter;
import org.apache.nifi.parameter.ParameterLookup;
import org.apache.nifi.search.SearchContext;
import java.util.Map;
+import java.util.Optional;
/**
*
@@ -58,7 +60,8 @@ public class StandardSearchContext implements SearchContext {
public PropertyValue getProperty(final PropertyDescriptor property) {
final String configuredValue =
processorNode.getRawPropertyValue(property);
final ResourceContext resourceContext = new
StandardResourceContext(new StandardResourceReferenceFactory(), property);
- return new StandardPropertyValue(resourceContext, configuredValue ==
null ? property.getDefaultValue() : configuredValue, controllerServiceLookup,
ParameterLookup.EMPTY);
+ final ParameterLookup parameterLookup = new
SensitivityMatchingParameterLookup(processorNode.getParameterLookup(),
property.isSensitive());
+ return new StandardPropertyValue(resourceContext, configuredValue ==
null ? property.getDefaultValue() : configuredValue, controllerServiceLookup,
parameterLookup);
}
@Override
@@ -66,4 +69,33 @@ public class StandardSearchContext implements SearchContext {
return processorNode.getRawPropertyValues();
}
+ /**
+ * Resolves only Parameters whose sensitivity matches the sensitivity of
the Property. A reference to a Parameter with
+ * mismatched sensitivity evaluates to an empty value, so a sensitive
Parameter value is never substituted into a non-sensitive Property.
+ */
+ private static class SensitivityMatchingParameterLookup implements
ParameterLookup {
+ private final ParameterLookup parameterLookup;
+ private final boolean sensitive;
+
+ private SensitivityMatchingParameterLookup(final ParameterLookup
parameterLookup, final boolean sensitive) {
+ this.parameterLookup = parameterLookup == null ? EMPTY :
parameterLookup;
+ this.sensitive = sensitive;
+ }
+
+ @Override
+ public Optional<Parameter> getParameter(final String parameterName) {
+ return parameterLookup.getParameter(parameterName)
+ .filter(parameter ->
parameter.getDescriptor().isSensitive() == sensitive);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return parameterLookup.isEmpty();
+ }
+
+ @Override
+ public long getVersion() {
+ return parameterLookup.getVersion();
+ }
+ }
}
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/TestStandardSearchContext.java
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/TestStandardSearchContext.java
new file mode 100644
index 00000000000..bdfb9b3f8e9
--- /dev/null
+++
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/TestStandardSearchContext.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.web.controller;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.components.resource.ResourceCardinality;
+import org.apache.nifi.components.resource.ResourceType;
+import org.apache.nifi.controller.ControllerServiceLookup;
+import org.apache.nifi.controller.ProcessorNode;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.parameter.Parameter;
+import org.apache.nifi.parameter.ParameterLookup;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class TestStandardSearchContext {
+
+ private static final String SCRIPTS_DIR_PARAMETER = "scripts.dir";
+
+ private static final String SECRET_PARAMETER = "secret";
+
+ private static final PropertyDescriptor SCRIPT_FILE = new
PropertyDescriptor.Builder()
+ .name("Script File")
+ .required(false)
+ .addValidator(Validator.VALID)
+ .identifiesExternalResource(ResourceCardinality.SINGLE,
ResourceType.FILE)
+ .expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
+ .build();
+
+ private static final PropertyDescriptor PASSWORD = new
PropertyDescriptor.Builder()
+ .name("Password")
+ .required(false)
+ .sensitive(true)
+ .addValidator(Validator.VALID)
+ .build();
+
+ @Mock
+ private ProcessorNode processorNode;
+
+ @Mock
+ private ControllerServiceLookup controllerServiceLookup;
+
+ private StandardSearchContext context;
+
+ @BeforeEach
+ void setContext() {
+ final Map<String, Parameter> parameters = Map.of(
+ SCRIPTS_DIR_PARAMETER, new
Parameter.Builder().name(SCRIPTS_DIR_PARAMETER).value("/opt/scripts").sensitive(false).build(),
+ SECRET_PARAMETER, new
Parameter.Builder().name(SECRET_PARAMETER).value("s3cr3t").sensitive(true).build()
+ );
+ when(processorNode.getParameterLookup()).thenReturn(new
MapParameterLookup(parameters));
+
+ context = new StandardSearchContext("search-me", processorNode,
controllerServiceLookup);
+ }
+
+ @Test
+ void getPropertyEvaluatedResolvesParameter() {
+
when(processorNode.getRawPropertyValue(SCRIPT_FILE)).thenReturn("#{scripts.dir}/file.groovy");
+
+ assertEquals("/opt/scripts/file.groovy",
context.getProperty(SCRIPT_FILE).evaluateAttributeExpressions().getValue());
+ }
+
+ @Test
+ void getPropertyValueRemainsRaw() {
+
when(processorNode.getRawPropertyValue(SCRIPT_FILE)).thenReturn("#{scripts.dir}/file.groovy");
+
+ assertEquals("#{scripts.dir}/file.groovy",
context.getProperty(SCRIPT_FILE).getValue());
+ }
+
+ @Test
+ void
getPropertyEvaluatedExcludesSensitiveParameterForNonSensitiveProperty() {
+
when(processorNode.getRawPropertyValue(SCRIPT_FILE)).thenReturn("#{secret}");
+
+ assertEquals("",
context.getProperty(SCRIPT_FILE).evaluateAttributeExpressions().getValue());
+ }
+
+ @Test
+ void getPropertyEvaluatedResolvesOnlyMatchingParameterInMixedReferences() {
+
when(processorNode.getRawPropertyValue(SCRIPT_FILE)).thenReturn("#{scripts.dir}/#{secret}");
+
+ assertEquals("/opt/scripts/",
context.getProperty(SCRIPT_FILE).evaluateAttributeExpressions().getValue());
+ }
+
+ @Test
+ void
getPropertyEvaluatedExcludesNonSensitiveParameterForSensitiveProperty() {
+
when(processorNode.getRawPropertyValue(PASSWORD)).thenReturn("#{scripts.dir}");
+
+ assertEquals("",
context.getProperty(PASSWORD).evaluateAttributeExpressions().getValue());
+ }
+
+ @Test
+ void getPropertyEvaluatedWithoutParameterContext() {
+ when(processorNode.getParameterLookup()).thenReturn(null);
+
when(processorNode.getRawPropertyValue(SCRIPT_FILE)).thenReturn("#{scripts.dir}/file.groovy");
+
+ assertEquals("/file.groovy",
context.getProperty(SCRIPT_FILE).evaluateAttributeExpressions().getValue());
+ }
+
+ private record MapParameterLookup(Map<String, Parameter> parameters)
implements ParameterLookup {
+ @Override
+ public Optional<Parameter> getParameter(final String parameterName) {
+ return Optional.ofNullable(parameters.get(parameterName));
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return parameters.isEmpty();
+ }
+
+ @Override
+ public long getVersion() {
+ return 0;
+ }
+ }
+}