From af365414e9393b521ea314028d7a49d07f005c9b Mon Sep 17 00:00:00 2001 From: Emilio Setiadarma Date: Thu, 24 Aug 2023 16:40:03 -0700 Subject: [PATCH] NIFI-11519 Fixed DBCPConnectionPool Sensitive Dynamic Properties - Added handling for property names marked as sensitive but not having the SENSITIVE prefix for backward compatibility This closes #7646 Signed-off-by: David Handermann --- .../java/org/apache/nifi/dbcp/DBCPConnectionPool.java | 7 ++++++- .../java/org/apache/nifi/dbcp/DBCPServiceTest.java | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java b/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java index d531257b0f..c5c735f7b4 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java @@ -272,7 +272,12 @@ public class DBCPConnectionPool extends AbstractDBCPConnectionPool implements DB .map(descriptor -> { final PropertyValue propertyValue = context.getProperty(descriptor); if (descriptor.isSensitive()) { - final String propertyName = StringUtils.substringAfter(descriptor.getName(), SENSITIVE_PROPERTY_PREFIX); + final String propertyName; + if (StringUtils.startsWith(descriptor.getName(), SENSITIVE_PROPERTY_PREFIX)) { + propertyName = StringUtils.substringAfter(descriptor.getName(), SENSITIVE_PROPERTY_PREFIX); + } else { + propertyName = descriptor.getName(); + } return new AbstractMap.SimpleEntry<>(propertyName, propertyValue.getValue()); } else { return new AbstractMap.SimpleEntry<>(descriptor.getName(), propertyValue.evaluateAttributeExpressions().getValue()); diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java b/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java index bb6b08e992..747791324b 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java @@ -32,6 +32,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.opentest4j.AssertionFailedError; import java.io.File; import java.io.IOException; @@ -162,6 +163,15 @@ public class DBCPServiceTest { assertConnectionNotNullDynamicProperty("SENSITIVE.create", "true"); } + @Test + public void testGetConnectionSensitiveDynamicPropertyWithoutPrefixAndWithPrefixShouldThrowException() { + runner.setProperty(service, "SENSITIVE.create", "true"); + runner.setProperty(service, "create", "true"); + + final AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> runner.enableControllerService(service)); + assertTrue(e.getMessage().contains("Duplicate")); + } + @Test public void testGetConnectionExecuteStatements() throws SQLException { runner.enableControllerService(service);