From 6ebd390330a806b0d5eb09e657dd670eff17d142 Mon Sep 17 00:00:00 2001 From: Domenico Francesco Bruscino Date: Tue, 30 Jan 2024 11:07:09 +0100 Subject: [PATCH] ARTEMIS-4587 Config security setting plugins by using broker properties --- .../core/server/SecuritySettingPlugin.java | 4 +++ .../config/impl/ConfigurationImplTest.java | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/SecuritySettingPlugin.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/SecuritySettingPlugin.java index 5d62c31662..5a287d3176 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/SecuritySettingPlugin.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/SecuritySettingPlugin.java @@ -25,6 +25,10 @@ import org.apache.activemq.artemis.core.settings.HierarchicalRepository; public interface SecuritySettingPlugin extends Serializable { + default void setInit(Map props) { + init(props); + } + /** * Initialize the plugin with the given configuration options. This method is called by the broker when the file-based * configuration is read (see {@code org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser#parseSecurity(org.w3c.dom.Element, org.apache.activemq.artemis.core.config.Configuration)}. diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java index 7f919af353..2e17ecc1e6 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java @@ -66,6 +66,7 @@ import org.apache.activemq.artemis.core.security.Role; import org.apache.activemq.artemis.core.server.ComponentConfigurationRoutingType; import org.apache.activemq.artemis.core.server.JournalType; import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType; +import org.apache.activemq.artemis.core.server.impl.LegacyLDAPSecuritySettingPlugin; import org.apache.activemq.artemis.core.server.plugin.impl.LoggingActiveMQServerPlugin; import org.apache.activemq.artemis.core.server.routing.KeyType; import org.apache.activemq.artemis.core.server.routing.policies.ConsistentHashModuloPolicy; @@ -2184,6 +2185,34 @@ public class ConfigurationImplTest extends ServerTestBase { Assert.assertTrue(configuration.getStatus().contains("LOG_ALL_EVENTS")); } + @Test + public void testSecuritySettingPluginFromBrokerProperties() throws Exception { + + final ConfigurationImpl configuration = new ConfigurationImpl(); + + Properties insertionOrderedProperties = new ConfigurationImpl.InsertionOrderedProperties(); + insertionOrderedProperties.put("securitySettingPlugins.\"org.apache.activemq.artemis.core.server.impl.LegacyLDAPSecuritySettingPlugin.class\".init", "initialContextFactory=com.sun.jndi.ldap.LdapCtxFactory,connectionURL=ldap://localhost:1024"); + + configuration.parsePrefixedProperties(insertionOrderedProperties, null); + + Assert.assertEquals(1, configuration.getSecuritySettingPlugins().size()); + Assert.assertEquals("com.sun.jndi.ldap.LdapCtxFactory", ((LegacyLDAPSecuritySettingPlugin)(configuration.getSecuritySettingPlugins().get(0))).getInitialContextFactory()); + Assert.assertEquals("ldap://localhost:1024", ((LegacyLDAPSecuritySettingPlugin)(configuration.getSecuritySettingPlugins().get(0))).getConnectionURL()); + + Assert.assertTrue(configuration.getStatus().contains("\"errors\":[]")); + + // verify invalid map errors out + insertionOrderedProperties = new ConfigurationImpl.InsertionOrderedProperties(); + + // possible to change any attribute, but plugins only registered on start + insertionOrderedProperties.put("securitySettingPlugins.\"org.apache.activemq.artemis.core.server.impl.LegacyLDAPSecuritySettingPlugin.class\".init", "initialContextFactory"); + + configuration.parsePrefixedProperties(insertionOrderedProperties, null); + + Assert.assertFalse(configuration.getStatus().contains("\"errors\":[]")); + Assert.assertTrue(configuration.getStatus().contains("initialContextFactory")); + } + /** * To test ARTEMIS-926 * @throws Throwable