Use namespace suffix instead of full namespace in SlingServletsSource config
authorBertrand Delacretaz <bdelacretaz@apache.org>
Thu, 18 Oct 2018 12:02:02 +0000 (14:02 +0200)
committerBertrand Delacretaz <bdelacretaz@apache.org>
Thu, 18 Oct 2018 12:02:02 +0000 (14:02 +0200)
README.md
src/main/java/org/apache/sling/capabilities/defaultsources/SlingServletsSource.java
src/test/java/org/apache/sling/capabilities/defaultsources/SlingServletsSourceTest.java

index 75ef9fd..28d0374 100644 (file)
--- a/README.md
+++ b/README.md
@@ -66,12 +66,13 @@ This module does not provide any active `CapabilitiesSource` out of the box, but
 
 With the example configuration below a `sling/capabilities` resource with 
 `namespace_patterns='servlets\.[A|B]'` and a path that matches `/var/capabilities/.*`
-produces the following output:
+produces the following output at `/var/capabilities/caps.json` with the resource shown 
+below:
 
     {
       "org.apache.sling.capabilities": {
         "data": {
-          "servlets.A": {
+          "org.apache.sling.servlets.testA": {
             "GetAclServlet_23102540": {
               "sling.servlet.extensions": "json",
               "sling.servlet.selectors": [
@@ -82,7 +83,7 @@ produces the following output:
               "sling.servlet.methods": "GET"
             }
           },
-          "servlets.B": {
+          "org.apache.sling.servlets.testB": {
             "ChangeUserPasswordServlet_2134633768": {
               "sling.servlet.selectors": "changePassword",
               "sling.servlet.resourceTypes": "sling/user",
@@ -93,28 +94,28 @@ produces the following output:
       }
     }
 
-The configured `servlets.C` namespace is omitted due to the `namespace_patterns` property.
+The configured `testC` namespace is omitted due to the `namespace_patterns` property of the resource shown below.
 
 Here's the required configuration, excerpted from `/system/console/status-Configurations`:
 
     PID = org.apache.sling.capabilities.internal.CapabilitiesServlet
     resourcePathPatterns = [/var/capabilities/.*]
-    
-    Factory PID = org.apache.sling.capabilities.defaultsources.SlingServletsSource
-    capabilitiesNamespace = servlets.A
-    servletsLdapFilter = (&(sling.servlet.extensions=json)(sling.servlet.selectors=acl))
-    
-    Factory PID = org.apache.sling.capabilities.defaultsources.SlingServletsSource
-    capabilitiesNamespace = servlets.B
-    servletsLdapFilter = (&(sling.servlet.resourceTypes=sling/user)(sling.servlet.selectors=changePassword))
 
-    Factory PID = org.apache.sling.capabilities.defaultsources.SlingServletsSource
-    capabilitiesNamespace = servlets.C
-    servletsLdapFilter = (sling.servlet.extensions=html)
+       Factory PID = org.apache.sling.capabilities.defaultsources.SlingServletsSource
+       capabilitiesNamespaceSuffix = testA
+       servletsLdapFilter = (&(sling.servlet.extensions=json)(sling.servlet.selectors=acl))    
+       
+       Factory PID = org.apache.sling.capabilities.defaultsources.SlingServletsSource
+       capabilitiesNamespaceSuffix = testB
+       servletsLdapFilter = (&(sling.servlet.resourceTypes=sling/user)(sling.servlet.selectors=changePassword))
+
+       Factory PID = org.apache.sling.capabilities.defaultsources.SlingServletsSource
+       capabilitiesNamespaceSuffix = testC
+       servletsLdapFilter = (sling.servlet.extensions=html)
 
 And a resource that then generates the above output can be created with
 
     curl -u admin:admin \
       -Fsling:resourceType=sling/capabilities \
-      -Fnamespace_patterns='servlets\.[A|B]' \
+      -Fnamespace_patterns='org\.apache\.sling\.servlets\.test[A|B]' \
       http://localhost:8080/var/capabilities/caps
\ No newline at end of file
index b196f66..e3d84a9 100644 (file)
@@ -54,10 +54,12 @@ public class SlingServletsSource implements CapabilitiesSource {
         String servletsLdapFilter() default "";
         
         @AttributeDefinition(
-            name = "Capabilities Namespace",
-            description = "Unique namespace that identifies this set of capabilities"
+            name = "Capabilities Namespace Suffix",
+            description = "Unique namespace suffix that identifies this set of capabilities."
+                + " Will be prefixed with '" + NAMESPACE_PREFIX
+                + "' to compute the actual capabilities namespace"
         )
-        String capabilitiesNamespace();
+        String capabilitiesNamespaceSuffix();
     }
     
     private String namespace;
@@ -65,11 +67,12 @@ public class SlingServletsSource implements CapabilitiesSource {
     private BundleContext bundleContext;
     
     private static final String SLING_SERVLET_PROPERTY_PREFIX = "sling.servlet.";
+    public static final String NAMESPACE_PREFIX = "org.apache.sling.servlets.";
     
     @Activate
     public void activate(Config cfg, ComponentContext ctx) {
         this.bundleContext = ctx.getBundleContext();
-        this.namespace = cfg.capabilitiesNamespace();
+        this.namespace = NAMESPACE_PREFIX + cfg.capabilitiesNamespaceSuffix();
         this.ldapFilter = cfg.servletsLdapFilter();
     }
 
index 884d54a..c831309 100644 (file)
@@ -64,7 +64,7 @@ public class SlingServletsSourceTest {
         assertNotNull("Expecting a ConfigurationAdmin service", ca);
         final Configuration cfg = ca.getConfiguration(SlingServletsSource.class.getName());
         final Dictionary<String, Object> props = new Hashtable<>();
-        props.put("capabilitiesNamespace", "TEST_NS");
+        props.put("capabilitiesNamespaceSuffix", "TEST_NS");
         props.put("servletsLdapFilter", "(sling.servlet.extensions=json)");
         cfg.update(props);
 
@@ -83,10 +83,10 @@ public class SlingServletsSourceTest {
     public void testServletsSource() throws Exception {
         final CapabilitiesSource src = context.getService(CapabilitiesSource.class);
         assertNotNull("Expecting a CapabilitiesSource", src);
+        assertEquals("Expecting namespace to match", "org.apache.sling.servlets.TEST_NS", src.getNamespace());
 
         final Map<String, Object> caps = src.getCapabilities();
         assertNotNull("Expecting to get Capabilities", caps);
-
         assertEquals("Expecting capabilities for 2 json servlets", 2, caps.size());
 
         final Pattern keyPattern = Pattern.compile("MockServlet_[0-9]+");