You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2022/06/03 07:49:34 UTC

[jackrabbit-oak] branch trunk updated: OAK-9793 : AbstractRestrictionProvider: validation to respect aggregation for unsupported paths

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

angela pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 71d94d6bc9 OAK-9793 : AbstractRestrictionProvider: validation to respect aggregation for unsupported paths
71d94d6bc9 is described below

commit 71d94d6bc94a33fcb9f33ef012b50ad1e177ffb3
Author: angela <an...@adobe.com>
AuthorDate: Fri Jun 3 09:49:25 2022 +0200

    OAK-9793 : AbstractRestrictionProvider: validation to respect aggregation for unsupported paths
---
 .../restriction/AbstractRestrictionProvider.java   |  7 ++-
 .../AbstractRestrictionProviderTest.java           | 59 ++++++++++++++++++++++
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java
index 94bee85b7f..4432f9c041 100644
--- a/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java
+++ b/oak-security-spi/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProvider.java
@@ -22,6 +22,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -159,8 +160,10 @@ public abstract class AbstractRestrictionProvider implements RestrictionProvider
     public void validateRestrictions(@Nullable String oakPath, @NotNull Tree aceTree) throws AccessControlException {
         Map<String, PropertyState> restrictionProperties = getRestrictionProperties(aceTree);
         if (isUnsupportedPath(oakPath)) {
-            if (!restrictionProperties.isEmpty()) {
-                throw new AccessControlException("Restrictions not supported with 'null' path.");
+            // test if there are any restrictions present that are not supported by another provider when used in a composite
+            Set<String> unsupportedNames = restrictionProperties.keySet().stream().filter(name -> !isSupportedByAnotherProvider(oakPath, name)).collect(Collectors.toSet());
+            if (!unsupportedNames.isEmpty()) {
+                throw new AccessControlException("Restrictions '"+unsupportedNames+"' not supported with path '"+oakPath+"'.");
             }
         } else {
             // supported path -> validate restrictions and test if mandatory
diff --git a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProviderTest.java b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProviderTest.java
index 5fbd419237..b4b38d707f 100644
--- a/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProviderTest.java
+++ b/oak-security-spi/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/restriction/AbstractRestrictionProviderTest.java
@@ -40,6 +40,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.function.Function;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
@@ -321,6 +322,64 @@ public class AbstractRestrictionProviderTest implements AccessControlConstants {
         restrictionProvider.validateRestrictions(null, getAceTree(restr));
     }
 
+    @Test
+    public void testValidateRestrictionsUnsupportedPathInComposite() throws Exception {
+        // different provider that supports rep:glob at the 'null' path
+        RestrictionProvider second = createSecondProvider(Collections.singletonMap(REP_GLOB, supported.get(REP_GLOB)), s -> false);
+
+        Restriction restr = second.createRestriction(null, REP_GLOB, globValue);
+        
+        // non-empty restrictions at unsupported path => must not fail if covered by a different provider
+        RestrictionProvider composite = CompositeRestrictionProvider.newInstance(restrictionProvider, second);
+        composite.validateRestrictions(null, getAceTree(restr));
+    }
+    
+    @Test
+    public void testValidateRestrictionsUnsupportedPathInComposite2() throws Exception {
+        Restriction restr = restrictionProvider.createRestriction(testPath, REP_GLOB, globValue);
+        Restriction mandatory = restrictionProvider.createRestriction(testPath, "mandatory", valueFactory.createValue(false));
+
+        // create a second provider that does not support restrictions at 'testpath'
+        RestrictionProvider second = createSecondProvider(Collections.singletonMap(REP_GLOB, supported.get(REP_GLOB)), testPath::equals);
+
+        RestrictionProvider composite = CompositeRestrictionProvider.newInstance(restrictionProvider, second);
+        composite.validateRestrictions(testPath, getAceTree(restr, mandatory));
+    }
+    
+    @Test(expected = AccessControlException.class)
+    public void testValidateRestrictionsUnsupportedPathInComposite3() throws Exception {
+        Restriction restr = restrictionProvider.createRestriction(testPath, REP_GLOB, globValue);
+        Restriction mandatory = restrictionProvider.createRestriction(testPath, "mandatory", valueFactory.createValue(false));
+
+        // create a second provider that does support rep:glob at null path (but not the 'mandatory' restriction)
+        RestrictionProvider second = createSecondProvider(Collections.singletonMap(REP_GLOB, supported.get(REP_GLOB)), s -> false);
+
+        // since 'mandatory' restriction is not supported the validation must fail
+        RestrictionProvider composite = CompositeRestrictionProvider.newInstance(restrictionProvider, second);
+        composite.validateRestrictions(null, getAceTree(restr, mandatory));
+    }
+    
+    @NotNull
+    private static RestrictionProvider createSecondProvider(@NotNull Map<String, RestrictionDefinition> supported, 
+                                                            @NotNull Function<String, Boolean> isUnsupportedFunction) {
+        return new AbstractRestrictionProvider(supported) {
+            @Override
+            protected boolean isUnsupportedPath(@Nullable String oakPath) {
+                return isUnsupportedFunction.apply(oakPath);
+            }
+
+            @Override
+            public @NotNull RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Tree tree) {
+                throw new UnsupportedOperationException();
+            }
+
+            @Override
+            public @NotNull RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Set<Restriction> restrictions) {
+                throw new UnsupportedOperationException();
+            }
+        };
+    }
+    
     @Test(expected = AccessControlException.class)
     public void testValidateRestrictionsWrongType() throws Exception {
         Restriction mand = restrictionProvider.createRestriction(testPath, "mandatory", valueFactory.createValue(true));