SLING-3930 - Service rankings from ResourceAccessGates are not properly handled

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1624823 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/resourceaccesssecurity/it/impl/gates/ApplicationGate1Ranking100.java b/src/main/java/org/apache/sling/resourceaccesssecurity/it/impl/gates/ApplicationGate1Ranking100.java
new file mode 100644
index 0000000..f3648a1
--- /dev/null
+++ b/src/main/java/org/apache/sling/resourceaccesssecurity/it/impl/gates/ApplicationGate1Ranking100.java
@@ -0,0 +1,28 @@
+package org.apache.sling.resourceaccesssecurity.it.impl.gates;

+

+import org.apache.felix.scr.annotations.Component;

+import org.apache.felix.scr.annotations.Properties;

+import org.apache.felix.scr.annotations.Property;

+import org.apache.felix.scr.annotations.Service;

+import org.apache.sling.resourceaccesssecurity.ResourceAccessGate;

+import org.osgi.framework.Constants;

+

+@Component

+@Service(value=ResourceAccessGate.class)

+@Properties({

+        @Property(name=ResourceAccessGate.PATH, label="Path", value="/test/(un|)secured-provider/read(-update|)/(app|mixed)/.*", 

+                description="The path is a regular expression for which resources the service should be called"),

+        @Property(name=ResourceAccessGate.OPERATIONS, value="read,update"),

+        @Property(name=ResourceAccessGate.CONTEXT, value=ResourceAccessGate.APPLICATION_CONTEXT),

+        @Property(name = Constants.SERVICE_RANKING, intValue = 100, propertyPrivate = false)

+})

+public class ApplicationGate1Ranking100 extends AResourceAccessGate {

+    

+    public static String GATE_ID = "appgate1ranking100";

+

+    @Override

+    protected String getGateId() {

+        return GATE_ID;

+    }

+

+}

diff --git a/src/main/java/org/apache/sling/resourceaccesssecurity/it/impl/gates/ApplicationGate1Ranking1000.java b/src/main/java/org/apache/sling/resourceaccesssecurity/it/impl/gates/ApplicationGate1Ranking1000.java
new file mode 100644
index 0000000..0989f95
--- /dev/null
+++ b/src/main/java/org/apache/sling/resourceaccesssecurity/it/impl/gates/ApplicationGate1Ranking1000.java
@@ -0,0 +1,28 @@
+package org.apache.sling.resourceaccesssecurity.it.impl.gates;

+

+import org.apache.felix.scr.annotations.Component;

+import org.apache.felix.scr.annotations.Properties;

+import org.apache.felix.scr.annotations.Property;

+import org.apache.felix.scr.annotations.Service;

+import org.apache.sling.resourceaccesssecurity.ResourceAccessGate;

+import org.osgi.framework.Constants;

+

+@Component

+@Service(value=ResourceAccessGate.class)

+@Properties({

+        @Property(name=ResourceAccessGate.PATH, label="Path", value="/test/(un|)secured-provider/read(-update|)/(app|mixed)/.*", 

+                description="The path is a regular expression for which resources the service should be called"),

+        @Property(name=ResourceAccessGate.OPERATIONS, value="read,update"),

+        @Property(name=ResourceAccessGate.CONTEXT, value=ResourceAccessGate.APPLICATION_CONTEXT),

+        @Property(name = Constants.SERVICE_RANKING, intValue = 1000, propertyPrivate = false)

+})

+public class ApplicationGate1Ranking1000 extends AResourceAccessGate {

+    

+    public static String GATE_ID = "appgate1ranking1000";

+

+    @Override

+    protected String getGateId() {

+        return GATE_ID;

+    }

+

+}

diff --git a/src/main/java/org/apache/sling/resourceaccesssecurity/it/impl/gates/FinalAppGate1Ranking100.java b/src/main/java/org/apache/sling/resourceaccesssecurity/it/impl/gates/FinalAppGate1Ranking100.java
new file mode 100644
index 0000000..ae7f5d2
--- /dev/null
+++ b/src/main/java/org/apache/sling/resourceaccesssecurity/it/impl/gates/FinalAppGate1Ranking100.java
@@ -0,0 +1,28 @@
+package org.apache.sling.resourceaccesssecurity.it.impl.gates;

+

+import org.apache.felix.scr.annotations.Component;

+import org.apache.felix.scr.annotations.Properties;

+import org.apache.felix.scr.annotations.Property;

+import org.apache.felix.scr.annotations.Service;

+import org.apache.sling.resourceaccesssecurity.ResourceAccessGate;

+import org.osgi.framework.Constants;

+

+@Component

+@Service(value=ResourceAccessGate.class)

+@Properties({

+        @Property(name=ResourceAccessGate.PATH, label="Path", value="/test/(un|)secured-provider/read(-update|)/(app|mixed)/.*", 

+                description="The path is a regular expression for which resources the service should be called"),

+        @Property(name=ResourceAccessGate.FINALOPERATIONS, value="read,update"),

+        @Property(name=ResourceAccessGate.CONTEXT, value=ResourceAccessGate.APPLICATION_CONTEXT),

+        @Property(name = Constants.SERVICE_RANKING, intValue = 100, propertyPrivate = false)

+})

+public class FinalAppGate1Ranking100 extends AResourceAccessGate {

+

+    public static String GATE_ID = "finalappgate1ranking100";

+

+    @Override

+    protected String getGateId() {

+        return GATE_ID;

+    }

+

+}

diff --git a/src/main/java/org/apache/sling/resourceaccesssecurity/it/impl/gates/FinalAppGate1Ranking1000.java b/src/main/java/org/apache/sling/resourceaccesssecurity/it/impl/gates/FinalAppGate1Ranking1000.java
new file mode 100644
index 0000000..670cec9
--- /dev/null
+++ b/src/main/java/org/apache/sling/resourceaccesssecurity/it/impl/gates/FinalAppGate1Ranking1000.java
@@ -0,0 +1,28 @@
+package org.apache.sling.resourceaccesssecurity.it.impl.gates;

+

+import org.apache.felix.scr.annotations.Component;

+import org.apache.felix.scr.annotations.Properties;

+import org.apache.felix.scr.annotations.Property;

+import org.apache.felix.scr.annotations.Service;

+import org.apache.sling.resourceaccesssecurity.ResourceAccessGate;

+import org.osgi.framework.Constants;

+

+@Component

+@Service(value=ResourceAccessGate.class)

+@Properties({

+        @Property(name=ResourceAccessGate.PATH, label="Path", value="/test/(un|)secured-provider/read(-update|)/(app|mixed)/.*", 

+                description="The path is a regular expression for which resources the service should be called"),

+        @Property(name=ResourceAccessGate.FINALOPERATIONS, value="read,update"),

+        @Property(name=ResourceAccessGate.CONTEXT, value=ResourceAccessGate.APPLICATION_CONTEXT),

+        @Property(name = Constants.SERVICE_RANKING, intValue = 1000, propertyPrivate = false)

+})

+public class FinalAppGate1Ranking1000 extends AResourceAccessGate {

+

+    public static String GATE_ID = "finalappgate1ranking1000";

+

+    @Override

+    protected String getGateId() {

+        return GATE_ID;

+    }

+

+}

diff --git a/src/test/java/org/apache/sling/resourceaccesssecurity/it/UnsecuredProviderResourceAccessSecurityTest.java b/src/test/java/org/apache/sling/resourceaccesssecurity/it/UnsecuredProviderResourceAccessSecurityTest.java
index b2351da..6b5333a 100644
--- a/src/test/java/org/apache/sling/resourceaccesssecurity/it/UnsecuredProviderResourceAccessSecurityTest.java
+++ b/src/test/java/org/apache/sling/resourceaccesssecurity/it/UnsecuredProviderResourceAccessSecurityTest.java
@@ -44,4 +44,39 @@
 
         testRead(getTestUsername(), getTestPassword(), path, 404);
     }
+    
+    @Test
+    public void testReadOnlyApplicationAccessGatePresent() throws Exception {
+        String path = "/test/unsecured-provider/read/app/appgate1-allowread/test.json";
+
+        testRead(getTestUsername(), getTestPassword(), path, 200);
+    }
+    
+    @Test
+    public void testCantReadOnlyApplicationAccessGatePresent() throws Exception {
+        String path = "/test/unsecured-provider/read/app/appgate1-denyread/test.json";
+
+        testRead(getTestUsername(), getTestPassword(), path, 404);
+    }
+    
+    @Test
+    public void testServiceRanking() throws Exception {
+        String path1 = "/test/unsecured-provider/read/app/appgate1-allowread_finalappgate1ranking1000-denyread/test.json";
+        String path2 = "/test/unsecured-provider/read/app/appgate1-allowread_finalappgate1ranking100-denyread/test.json";
+        String path3 = "/test/unsecured-provider/read/app/finalappgate1-allowread_finalappgate1ranking1000-denyread/test.json";
+        String path4 = "/test/unsecured-provider/read/app/appgate1ranking1000-allowread_finalappgate1ranking100-denyread/test.json";
+        String path5 = "/test/unsecured-provider/read/app/appgate1ranking100-allowread_finalappgate1-denyread/test.json";
+        String path6 = "/test/unsecured-provider/read/app/appgate1-allowread_appgate1ranking1000-denyread/test.json";
+        String path7 = "/test/unsecured-provider/read/app/appgate1ranking100-allowread_appgate1ranking1000-denyread/test.json";
+
+        testRead(getTestUsername(), getTestPassword(), path1, 404);
+        testRead(getTestUsername(), getTestPassword(), path2, 404);
+        testRead(getTestUsername(), getTestPassword(), path3, 404);
+        testRead(getTestUsername(), getTestPassword(), path4, 200);
+        testRead(getTestUsername(), getTestPassword(), path5, 200);
+        testRead(getTestUsername(), getTestPassword(), path6, 200);
+        testRead(getTestUsername(), getTestPassword(), path7, 200);
+    }
+    
+    
 }