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 <exceptionfactory@apache.org>
This commit is contained in:
Emilio Setiadarma 2023-08-24 16:40:03 -07:00 committed by exceptionfactory
parent a5ca73b2da
commit af365414e9
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
2 changed files with 16 additions and 1 deletions

View File

@ -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());

View File

@ -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);