This is an automated email from the ASF dual-hosted git repository. cziegeler pushed a commit to branch issues/SLING-11741 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-base.git
The following commit(s) were added to refs/heads/issues/SLING-11741 by this push: new 54e478e Use constants for pid/factory pid 54e478e is described below commit 54e478ee77e20a432f1bba7f42234b2b8541b7a9 Author: Carsten Ziegeler <cziege...@apache.org> AuthorDate: Sun Jun 4 10:22:00 2023 +0200 Use constants for pid/factory pid --- .../apache/sling/jcr/base/internal/AllowListFragment.java | 3 ++- .../apache/sling/jcr/base/internal/ConfigurationUpdater.java | 5 +++-- .../apache/sling/jcr/base/internal/LoginAdminAllowList.java | 4 +++- .../sling/jcr/base/internal/ConfigurationUpdaterTest.java | 12 ++++++------ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/apache/sling/jcr/base/internal/AllowListFragment.java b/src/main/java/org/apache/sling/jcr/base/internal/AllowListFragment.java index d59654c..ea51e81 100644 --- a/src/main/java/org/apache/sling/jcr/base/internal/AllowListFragment.java +++ b/src/main/java/org/apache/sling/jcr/base/internal/AllowListFragment.java @@ -55,13 +55,14 @@ import static java.util.Arrays.asList; } @Component( - configurationPid = "org.apache.sling.jcr.base.internal.LoginAdminAllowList.fragment", + configurationPid = AllowListFragment.FACTORY_PID, configurationPolicy = ConfigurationPolicy.REQUIRE, service = AllowListFragment.class ) @Designate(ocd = Configuration.class, factory = true) public class AllowListFragment { + public static final String FACTORY_PID = "org.apache.sling.jcr.base.LoginAdminAllowList.fragment"; private final String name; private final Set<String> bundles; diff --git a/src/main/java/org/apache/sling/jcr/base/internal/ConfigurationUpdater.java b/src/main/java/org/apache/sling/jcr/base/internal/ConfigurationUpdater.java index 68b9156..9a0ba70 100644 --- a/src/main/java/org/apache/sling/jcr/base/internal/ConfigurationUpdater.java +++ b/src/main/java/org/apache/sling/jcr/base/internal/ConfigurationUpdater.java @@ -43,14 +43,15 @@ import org.slf4j.LoggerFactory; public class ConfigurationUpdater implements ConfigurationListener { static final String LOGIN_ADMIN_WHITELIST_PID = "org.apache.sling.jcr.base.internal.LoginAdminWhitelist"; - static final String LOGIN_ADMIN_ALLOWLIST_PID = "org.apache.sling.jcr.base.internal.LoginAdminAllowList"; + static final String LOGIN_ADMIN_ALLOWLIST_PID = LoginAdminAllowList.PID; private static final Map<String, String> LOGIN_ADMIN_WHITELIST_PROPS_TO_REPLACE = new HashMap<>(); static { LOGIN_ADMIN_WHITELIST_PROPS_TO_REPLACE.put("whitelist.bypass", "allowlist.bypass"); LOGIN_ADMIN_WHITELIST_PROPS_TO_REPLACE.put("whitelist.bundles.regexp", "allowlist.bundles.regexp"); } - private static final String ALLOWLIST_FRAGMENT_PID = "org.apache.sling.jcr.base.internal.LoginAdminAllowList.fragment"; + private static final String WHITELIST_FRAGMENT_PID = "org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment"; + private static final String ALLOWLIST_FRAGMENT_PID = AllowListFragment.FACTORY_PID; private static final Map<String, String> FRAGMENT_PROPS_TO_REPLACE = new HashMap<>(); static { diff --git a/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminAllowList.java b/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminAllowList.java index cb7631b..8ae079e 100644 --- a/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminAllowList.java +++ b/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminAllowList.java @@ -46,12 +46,14 @@ import static org.apache.sling.commons.osgi.PropertiesUtil.toStringArray; * The default configuration lets a few trusted Sling bundles * use the loginAdministrative method. */ -@Component(service = LoginAdminAllowList.class) +@Component(service = LoginAdminAllowList.class, configurationPid = LoginAdminAllowList.PID) @Designate( ocd = LoginAdminAllowListConfiguration.class ) public class LoginAdminAllowList { + public static final String PID = "org.apache.sling.jcr.base.LoginAdminAllowList"; + private static final Logger LOG = LoggerFactory.getLogger(LoginAdminAllowList.class); private volatile ConfigurationState config; diff --git a/src/test/java/org/apache/sling/jcr/base/internal/ConfigurationUpdaterTest.java b/src/test/java/org/apache/sling/jcr/base/internal/ConfigurationUpdaterTest.java index 7b78759..00696b3 100644 --- a/src/test/java/org/apache/sling/jcr/base/internal/ConfigurationUpdaterTest.java +++ b/src/test/java/org/apache/sling/jcr/base/internal/ConfigurationUpdaterTest.java @@ -49,7 +49,7 @@ public class ConfigurationUpdaterTest { when(mockSourceConfiguration.getProperties()).thenReturn(sourceProperties); when(mockConfigurationAdmin.listConfigurations("(service.pid=org.apache.sling.jcr.base.internal.LoginAdminWhitelist)")).thenReturn(new Configuration[] {mockSourceConfiguration}); - when(mockConfigurationAdmin.getConfiguration("org.apache.sling.jcr.base.internal.LoginAdminAllowList", null)).thenReturn(mockTargetConfiguration); + when(mockConfigurationAdmin.getConfiguration(LoginAdminAllowList.PID, null)).thenReturn(mockTargetConfiguration); final Dictionary<String, Object> expectedProperties = new Hashtable<>(); expectedProperties.put("allowlist.bypass", "whitelistNameValue"); @@ -59,7 +59,7 @@ public class ConfigurationUpdaterTest { new ConfigurationUpdater(mockConfigurationAdmin); verify(mockConfigurationAdmin).listConfigurations("(service.pid=org.apache.sling.jcr.base.internal.LoginAdminWhitelist)"); - verify(mockConfigurationAdmin).getConfiguration("org.apache.sling.jcr.base.internal.LoginAdminAllowList", null); + verify(mockConfigurationAdmin).getConfiguration(LoginAdminAllowList.PID, null); final ArgumentCaptor<Dictionary> targetPropertiesCaptor = ArgumentCaptor.forClass(Dictionary.class); verify(mockTargetConfiguration).update(targetPropertiesCaptor.capture()); assertEquals(expectedProperties, targetPropertiesCaptor.getValue()); @@ -79,7 +79,7 @@ public class ConfigurationUpdaterTest { when(mockSourceConfiguration.getFactoryPid()).thenReturn("org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment"); when(mockSourceConfiguration.getPid()).thenReturn("org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment~foo"); when(mockConfigurationAdmin.listConfigurations("(service.factoryPid=org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment)")).thenReturn(new Configuration[] {mockSourceConfiguration}); - when(mockConfigurationAdmin.getFactoryConfiguration("org.apache.sling.jcr.base.internal.LoginAdminAllowList.fragment", "foo", null)).thenReturn(mockTargetConfiguration); + when(mockConfigurationAdmin.getFactoryConfiguration(AllowListFragment.FACTORY_PID, "foo", null)).thenReturn(mockTargetConfiguration); final Dictionary<String, Object> expectedProperties = new Hashtable<>(); expectedProperties.put("allowlist.name", "whitelistNameValue"); @@ -89,7 +89,7 @@ public class ConfigurationUpdaterTest { new ConfigurationUpdater(mockConfigurationAdmin); verify(mockConfigurationAdmin).listConfigurations("(service.factoryPid=org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment)"); - verify(mockConfigurationAdmin).getFactoryConfiguration("org.apache.sling.jcr.base.internal.LoginAdminAllowList.fragment", "foo", null); + verify(mockConfigurationAdmin).getFactoryConfiguration(AllowListFragment.FACTORY_PID, "foo", null); final ArgumentCaptor<Dictionary> targetPropertiesCaptor = ArgumentCaptor.forClass(Dictionary.class); verify(mockTargetConfiguration).update(targetPropertiesCaptor.capture()); assertEquals(expectedProperties, targetPropertiesCaptor.getValue()); @@ -109,7 +109,7 @@ public class ConfigurationUpdaterTest { when(mockSourceConfiguration.getFactoryPid()).thenReturn("org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment"); when(mockSourceConfiguration.getPid()).thenReturn("org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment-randomid"); when(mockConfigurationAdmin.listConfigurations("(service.factoryPid=org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment)")).thenReturn(new Configuration[] {mockSourceConfiguration}); - when(mockConfigurationAdmin.createFactoryConfiguration("org.apache.sling.jcr.base.internal.LoginAdminAllowList.fragment", null)).thenReturn(mockTargetConfiguration); + when(mockConfigurationAdmin.createFactoryConfiguration(AllowListFragment.FACTORY_PID, null)).thenReturn(mockTargetConfiguration); final Dictionary<String, Object> expectedProperties = new Hashtable<>(); expectedProperties.put("allowlist.name", "whitelistNameValue"); @@ -119,7 +119,7 @@ public class ConfigurationUpdaterTest { new ConfigurationUpdater(mockConfigurationAdmin); verify(mockConfigurationAdmin).listConfigurations("(service.factoryPid=org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment)"); - verify(mockConfigurationAdmin).createFactoryConfiguration("org.apache.sling.jcr.base.internal.LoginAdminAllowList.fragment", null); + verify(mockConfigurationAdmin).createFactoryConfiguration(AllowListFragment.FACTORY_PID, null); final ArgumentCaptor<Dictionary> targetPropertiesCaptor = ArgumentCaptor.forClass(Dictionary.class); verify(mockTargetConfiguration).update(targetPropertiesCaptor.capture()); assertEquals(expectedProperties, targetPropertiesCaptor.getValue());