This is an automated email from the ASF dual-hosted git repository.
exceptionfactory 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 af365414e9 NIFI-11519 Fixed DBCPConnectionPool Sensitive Dynamic
Properties
af365414e9 is described below
commit af365414e9393b521ea314028d7a49d07f005c9b
Author: Emilio Setiadarma <[email protected]>
AuthorDate: Thu Aug 24 16:40:03 2023 -0700
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 <[email protected]>
---
.../src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java | 7 ++++++-
.../src/test/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);