You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2021/05/07 11:33:08 UTC

[sling-org-apache-sling-feature-cpconverter] branch SLING-10359 created (now 3ecd4d8)

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

angela pushed a change to branch SLING-10359
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git.


      at 3ecd4d8  SLING-10359 : RepPrincipalPolicyEntryHandler: rep:effectivePath is defined to be of type PATH

This branch includes the following new commits:

     new 3ecd4d8  SLING-10359 : RepPrincipalPolicyEntryHandler: rep:effectivePath is defined to be of type PATH

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-org-apache-sling-feature-cpconverter] 01/01: SLING-10359 : RepPrincipalPolicyEntryHandler: rep:effectivePath is defined to be of type PATH

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

angela pushed a commit to branch SLING-10359
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git

commit 3ecd4d8a7f745da5a377c99c1c82bb285592e5a6
Author: angela <an...@adobe.com>
AuthorDate: Fri May 7 13:32:54 2021 +0200

    SLING-10359 : RepPrincipalPolicyEntryHandler: rep:effectivePath is defined to be of type PATH
---
 .../handlers/RepPrincipalPolicyEntryHandler.java        | 16 +++++++++++++++-
 .../handlers/RepPrincipalPolicyEntryHandlerTest.java    | 17 +++++++++++++++++
 .../system/services/random1/_rep_principalPolicy.xml    |  2 +-
 .../system/services/random2/_rep_principalPolicy.xml    |  2 +-
 .../system/services/random3/_rep_principalPolicy.xml    |  2 +-
 .../home/users/system/services/random4/.content.xml     |  4 ++--
 .../system/services/random4/_rep_principalPolicy.xml    |  2 +-
 .../system/services/{random4 => random5}/.content.xml   |  4 ++--
 .../{random4 => random5}/_rep_principalPolicy.xml       |  4 ++--
 9 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandler.java b/src/main/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandler.java
index bbce52a..933dc7a 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandler.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandler.java
@@ -20,6 +20,7 @@ import org.apache.sling.feature.cpconverter.accesscontrol.AccessControlEntry;
 import org.apache.sling.feature.cpconverter.accesscontrol.AclManager;
 import org.apache.sling.feature.cpconverter.shared.RepoPath;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 
@@ -78,7 +79,7 @@ public final class RepPrincipalPolicyEntryHandler extends AbstractPolicyEntryHan
                         throw new IllegalStateException("isolated principal-based access control entry. no principal found.");
                     }
                     List<String> privileges = extractValues(attributes.getValue(REP_PRIVILEGES));
-                    RepoPath effectivePath = new RepoPath(attributes.getValue(REP_EFFECTIVE_PATH));
+                    RepoPath effectivePath = new RepoPath(extractEffectivePath(attributes.getValue(REP_EFFECTIVE_PATH)));
 
                     AccessControlEntry ace = new AccessControlEntry(true, privileges, effectivePath, true);
                     // NOTE: nt-definition doesn't allow for jr2-stype restrictions defined right below the entry.
@@ -122,5 +123,18 @@ public final class RepPrincipalPolicyEntryHandler extends AbstractPolicyEntryHan
                 return super.isRestriction(attributeName);
             }
         }
+        
+        @NotNull
+        private static String extractEffectivePath(@Nullable String value) {
+            if (value == null) {
+                return "";
+            }
+            if (value.startsWith("{Path}")) {
+                return value.substring("{Path}".length());
+            } else {
+                // malformed content package that defines rep:effectivePath as prop of type String instead of Path
+                return value;
+            }
+        }
     }
 }
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandlerTest.java b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandlerTest.java
index 2700c36..53ea09c 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandlerTest.java
@@ -145,6 +145,23 @@ public final class RepPrincipalPolicyEntryHandlerTest {
         assertFalse(operations.isEmpty());
     }
 
+    @Test
+    public void parsePolicyWithWrongTypeEffectivePath() throws Exception {
+        Extension repoinitExtension = parseAndSetRepoinit("service4", "random5").getRepoinitExtension();
+        String expected = normalize(
+                "create service user service4 with path system/services\n" +
+                        "set principal ACL for service4\n" +
+                        "    allow jcr:read on /effective/path/of/type/string\n" +
+                        "end\n");
+
+        String actual = repoinitExtension.getText();
+        assertEquals(expected, actual);
+
+        RepoInitParser repoInitParser = new RepoInitParserService();
+        List<Operation> operations = repoInitParser.parse(new StringReader(actual));
+        assertFalse(operations.isEmpty());
+    }
+
     @NotNull
     private static SystemUser createSystemUser(@NotNull String systemUsersName, @NotNull String nodeName) {
         RepoPath repoPath = new RepoPath("/home/users/system/services/"+nodeName);
diff --git a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random1/_rep_principalPolicy.xml b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random1/_rep_principalPolicy.xml
index e55c57f..26e5f08 100644
--- a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random1/_rep_principalPolicy.xml
+++ b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random1/_rep_principalPolicy.xml
@@ -21,6 +21,6 @@
     <entry0
             jcr:primaryType="rep:PrincipalEntry"
             rep:privileges="{Name}[jcr:read,jcr:readAccessControl]"
-            rep:effectivePath="/asd/public">
+            rep:effectivePath="{Path}/asd/public">
     </entry0>
 </jcr:root>
diff --git a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random2/_rep_principalPolicy.xml b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random2/_rep_principalPolicy.xml
index d2da38d..b5b2a03 100644
--- a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random2/_rep_principalPolicy.xml
+++ b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random2/_rep_principalPolicy.xml
@@ -21,7 +21,7 @@
     <entry0
             jcr:primaryType="rep:PrincipalEntry"
             rep:privileges="{Name}[jcr:read]"
-            rep:effectivePath="/asd/public">
+            rep:effectivePath="{Path}/asd/public">
         <rep:restrictions
                 jcr:primaryType="rep:Restrictions"
                 rep:ntNames="{Name}[nt:folder,sling:Folder]"
diff --git a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random3/_rep_principalPolicy.xml b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random3/_rep_principalPolicy.xml
index f5048c0..69653d0 100644
--- a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random3/_rep_principalPolicy.xml
+++ b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random3/_rep_principalPolicy.xml
@@ -21,6 +21,6 @@
     <entry0
             jcr:primaryType="rep:PrincipalEntry"
             rep:privileges="{Name}[jcr:all]"
-            rep:effectivePath="/home/users/system/services/random3/subtree">
+            rep:effectivePath="{Path}/home/users/system/services/random3/subtree">
     </entry0>
 </jcr:root>
diff --git a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/.content.xml b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/.content.xml
index 327ffdf..9f0a778 100644
--- a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/.content.xml
+++ b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/.content.xml
@@ -18,5 +18,5 @@
 <jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
           jcr:primaryType="rep:SystemUser"
           jcr:uuid="342acedc-ac4a-3044-93d0-3288d39668af"
-          rep:authorizableId="service3"
-          rep:principalName="service3"/>
+          rep:authorizableId="service4"
+          rep:principalName="service4"/>
diff --git a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/_rep_principalPolicy.xml b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/_rep_principalPolicy.xml
index eff8224..9b9e602 100644
--- a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/_rep_principalPolicy.xml
+++ b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/_rep_principalPolicy.xml
@@ -21,6 +21,6 @@
     <entry0
             jcr:primaryType="rep:PrincipalEntry"
             rep:privileges="{Name}[jcr:read,rep:userManagement]"
-            rep:effectivePath="/home/users/system/services/random3">
+            rep:effectivePath="{Path}/home/users/system/services/random3">
     </entry0>
 </jcr:root>
diff --git a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/.content.xml b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random5/.content.xml
similarity index 92%
copy from src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/.content.xml
copy to src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random5/.content.xml
index 327ffdf..9f0a778 100644
--- a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/.content.xml
+++ b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random5/.content.xml
@@ -18,5 +18,5 @@
 <jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
           jcr:primaryType="rep:SystemUser"
           jcr:uuid="342acedc-ac4a-3044-93d0-3288d39668af"
-          rep:authorizableId="service3"
-          rep:principalName="service3"/>
+          rep:authorizableId="service4"
+          rep:principalName="service4"/>
diff --git a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/_rep_principalPolicy.xml b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random5/_rep_principalPolicy.xml
similarity index 88%
copy from src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/_rep_principalPolicy.xml
copy to src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random5/_rep_principalPolicy.xml
index eff8224..8f21635 100644
--- a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random4/_rep_principalPolicy.xml
+++ b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/services/random5/_rep_principalPolicy.xml
@@ -20,7 +20,7 @@
           rep:principalName="service4">
     <entry0
             jcr:primaryType="rep:PrincipalEntry"
-            rep:privileges="{Name}[jcr:read,rep:userManagement]"
-            rep:effectivePath="/home/users/system/services/random3">
+            rep:privileges="{Name}[jcr:read]"
+            rep:effectivePath="/effective/path/of/type/string">
     </entry0>
 </jcr:root>