You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2018/10/18 12:02:29 UTC

[sling-org-apache-sling-capabilities] branch master updated: Use namespace suffix instead of full namespace in SlingServletsSource config

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-capabilities.git


The following commit(s) were added to refs/heads/master by this push:
     new f8eff93  Use namespace suffix instead of full namespace in SlingServletsSource config
f8eff93 is described below

commit f8eff93002e58a872af00022bf1ac8dcc7006925
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Oct 18 14:02:02 2018 +0200

    Use namespace suffix instead of full namespace in SlingServletsSource config
---
 README.md                                          | 33 +++++++++++-----------
 .../defaultsources/SlingServletsSource.java        | 11 +++++---
 .../defaultsources/SlingServletsSourceTest.java    |  4 +--
 3 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/README.md b/README.md
index 75ef9fd..28d0374 100644
--- 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
diff --git a/src/main/java/org/apache/sling/capabilities/defaultsources/SlingServletsSource.java b/src/main/java/org/apache/sling/capabilities/defaultsources/SlingServletsSource.java
index b196f66..e3d84a9 100644
--- a/src/main/java/org/apache/sling/capabilities/defaultsources/SlingServletsSource.java
+++ b/src/main/java/org/apache/sling/capabilities/defaultsources/SlingServletsSource.java
@@ -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();
     }
 
diff --git a/src/test/java/org/apache/sling/capabilities/defaultsources/SlingServletsSourceTest.java b/src/test/java/org/apache/sling/capabilities/defaultsources/SlingServletsSourceTest.java
index 884d54a..c831309 100644
--- a/src/test/java/org/apache/sling/capabilities/defaultsources/SlingServletsSourceTest.java
+++ b/src/test/java/org/apache/sling/capabilities/defaultsources/SlingServletsSourceTest.java
@@ -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]+");