From 0456b8845a816f6183e4eaac025c3d2d66e17f29 Mon Sep 17 00:00:00 2001 From: Domenico Francesco Bruscino Date: Tue, 22 Dec 2020 14:31:41 +0100 Subject: [PATCH] ARTEMIS-3041 Allow encrypted data source property values --- .../storage/DatabaseStorageConfiguration.java | 4 ++ .../impl/FileConfigurationParser.java | 7 +++- .../impl/DatabaseStoreConfigurationTest.java | 10 +++++ ...database-store-with-data-source-config.xml | 41 +++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 artemis-server/src/test/resources/database-store-with-data-source-config.xml diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/storage/DatabaseStorageConfiguration.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/storage/DatabaseStorageConfiguration.java index ebd824d921..03c9133f5f 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/storage/DatabaseStorageConfiguration.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/storage/DatabaseStorageConfiguration.java @@ -230,6 +230,10 @@ public class DatabaseStorageConfiguration implements StoreConfiguration { } } + public String getDataSourceProperty(String key) { + return (String)dataSourceProperties.get(key); + } + public String getDataSourceClassName() { return dataSourceClassName; } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java index 56d289f7a8..62740429d8 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java @@ -1764,7 +1764,12 @@ public final class FileConfigurationParser extends XMLConfigurationUtil { NodeList propertyNodeList = storeNode.getElementsByTagName("data-source-property"); for (int i = 0; i < propertyNodeList.getLength(); i++) { Element propertyNode = (Element) propertyNodeList.item(i); - conf.addDataSourceProperty(propertyNode.getAttributeNode("key").getValue(), propertyNode.getAttributeNode("value").getValue()); + final String propertyName = propertyNode.getAttributeNode("key").getValue(); + String propertyValue = propertyNode.getAttributeNode("value").getValue(); + if (propertyValue != null && PasswordMaskingUtil.isEncMasked(propertyValue)) { + propertyValue = PasswordMaskingUtil.resolveMask(mainConfig.isMaskPassword(), propertyValue, mainConfig.getPasswordCodec()); + } + conf.addDataSourceProperty(propertyName, propertyValue); } } diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/DatabaseStoreConfigurationTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/DatabaseStoreConfigurationTest.java index d9908416dc..c621528cde 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/DatabaseStoreConfigurationTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/DatabaseStoreConfigurationTest.java @@ -40,6 +40,16 @@ public class DatabaseStoreConfigurationTest extends ActiveMQTestBase { assertEquals("targetpassword", storeConfiguration.getJdbcPassword()); } + @Test + public void databaseStoreConfigWithDataSourceTest() throws Exception { + Configuration configuration = createConfiguration("database-store-with-data-source-config.xml"); + ActiveMQServerImpl server = new ActiveMQServerImpl(configuration); + DatabaseStorageConfiguration storeConfiguration = (DatabaseStorageConfiguration) server.getConfiguration().getStoreConfiguration(); + assertEquals(StoreConfiguration.StoreType.DATABASE, storeConfiguration.getStoreType()); + assertEquals("sourcepassword", storeConfiguration.getDataSourceProperty("username")); + assertEquals("targetpassword", storeConfiguration.getDataSourceProperty("password")); + } + @Test public void testOracle12TableSize() { for (SQLProvider.DatabaseStoreType storeType : SQLProvider.DatabaseStoreType.values()) { diff --git a/artemis-server/src/test/resources/database-store-with-data-source-config.xml b/artemis-server/src/test/resources/database-store-with-data-source-config.xml new file mode 100644 index 0000000000..fc03a75eb0 --- /dev/null +++ b/artemis-server/src/test/resources/database-store-with-data-source-config.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + BINDINGS_TABLE + MESSAGE_TABLE + LARGE_MESSAGE_TABLE + PAGE_STORE_TABLE + + + +