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

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

commit beab30a0923462467345cb1b93c8a6e5a7813f1f
Author: angela <[email protected]>
AuthorDate: Thu Dec 3 11:21:24 2020 +0100

    SLING-9970 : SystemUser.getPath doesn't reflect the repository path
---
 .../accesscontrol/AccessControlEntry.java          | 11 ++---------
 .../accesscontrol/DefaultAclManager.java           |  2 +-
 .../handlers/RepPolicyEntryHandler.java            | 10 +++-------
 .../handlers/SystemUsersEntryHandler.java          |  3 ++-
 .../cpconverter/accesscontrol/AclManagerTest.java  |  2 +-
 .../handlers/SystemUsersEntryHandlerTest.java      | 15 +++++++++++++++
 .../system/_my_feature/_my_user-node/.content.xml  | 22 ++++++++++++++++++++++
 7 files changed, 46 insertions(+), 19 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AccessControlEntry.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AccessControlEntry.java
index b6b850b..f07eef7 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AccessControlEntry.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/AccessControlEntry.java
@@ -30,16 +30,13 @@ public final class AccessControlEntry {
 
     private final String privileges;
 
-    private final RepoPath path;
-
     private final RepoPath repositoryPath;
 
     private final List<String> restrictions = new LinkedList<>();
 
-    public AccessControlEntry(boolean isAllow, String privileges, RepoPath 
path, RepoPath repositoryPath) {
+    public AccessControlEntry(boolean isAllow, String privileges, RepoPath 
repositoryPath) {
         this.isAllow = isAllow;
         this.privileges = privileges;
-        this.path = path;
         this.repositoryPath = repositoryPath;
     }
 
@@ -57,10 +54,6 @@ public final class AccessControlEntry {
         return privileges;
     }
 
-    public RepoPath getPath() {
-        return path;
-    }
-
     public RepoPath getRepositoryPath() {
         return repositoryPath;
     }
@@ -76,7 +69,7 @@ public final class AccessControlEntry {
                + ", privileges="
                + privileges
                + ", path="
-               + path
+               + repositoryPath
                + ", restrictions="
                + restrictions
                + "]";
diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java
index e645faf..63084f2 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/accesscontrol/DefaultAclManager.java
@@ -149,7 +149,7 @@ public final class DefaultAclManager implements AclManager {
             while (authorizationsIterator.hasNext()) {
                 AccessControlEntry acl = authorizationsIterator.next();
 
-                if (acl.getPath().startsWith(systemUser.getPath())) {
+                if (acl.getRepositoryPath().startsWith(systemUser.getPath())) {
                     authorizationsIterator.remove();
                 }
             }
diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandler.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandler.java
index 130ce41..38b9204 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandler.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandler.java
@@ -79,8 +79,7 @@ public final class RepPolicyEntryHandler extends 
AbstractRegexEntryHandler {
         StringWriter stringWriter = new StringWriter();
         handler.setResult(new StreamResult(stringWriter));
 
-        RepPolicyParser systemUserParser = new RepPolicyParser(new 
RepoPath(resourcePath),
-                                                               new 
RepoPath(PlatformNameFormat.getRepositoryPath(resourcePath)),
+        RepPolicyParser systemUserParser = new RepPolicyParser(new 
RepoPath(PlatformNameFormat.getRepositoryPath(resourcePath)),
                                                                
converter.getAclManager(),
                                                                handler);
         boolean hasRejectedAcls;
@@ -124,8 +123,6 @@ public final class RepPolicyEntryHandler extends 
AbstractRegexEntryHandler {
 
         private final Stack<AccessControlEntry> acls = new Stack<>();
 
-        private final RepoPath path;
-
         private final RepoPath repositoryPath;
 
         private final AclManager aclManager;
@@ -140,9 +137,8 @@ public final class RepPolicyEntryHandler extends 
AbstractRegexEntryHandler {
         // just internal pointer for every iteration
         private boolean processCurrentAcl = false;
 
-        public RepPolicyParser(RepoPath path, RepoPath repositoryPath, 
AclManager aclManager, TransformerHandler handler) {
+        public RepPolicyParser(RepoPath repositoryPath, AclManager aclManager, 
TransformerHandler handler) {
             super(REP_ACL);
-            this.path = path;
             this.repositoryPath = repositoryPath;
             this.aclManager = aclManager;
             this.handler = handler;
@@ -165,7 +161,7 @@ public final class RepPolicyEntryHandler extends 
AbstractRegexEntryHandler {
 
                     String privileges = 
extractValue(attributes.getValue(REP_PRIVILEGES));
 
-                    AccessControlEntry acl = new AccessControlEntry(isAllow, 
privileges, path, repositoryPath);
+                    AccessControlEntry acl = new AccessControlEntry(isAllow, 
privileges, repositoryPath);
 
                     processCurrentAcl = aclManager.addAcl(principalName, acl);
                     if (processCurrentAcl) {
diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/SystemUsersEntryHandler.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/SystemUsersEntryHandler.java
index 081c351..091ffe9 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/SystemUsersEntryHandler.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/SystemUsersEntryHandler.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.feature.cpconverter.handlers;
 
+import org.apache.jackrabbit.vault.util.PlatformNameFormat;
 import org.xml.sax.Attributes;
 
 import org.apache.jackrabbit.vault.fs.io.Archive;
@@ -42,7 +43,7 @@ public final class SystemUsersEntryHandler extends 
AbstractRegexEntryHandler {
             path = matcher.group(1);
         }
 
-        RepoPath currentPath = new RepoPath(path).getParent();
+        RepoPath currentPath = new 
RepoPath(PlatformNameFormat.getRepositoryPath(path)).getParent();
 
         SystemUserParser systemUserParser = new SystemUserParser(converter, 
currentPath);
         try (InputStream input = archive.openInputStream(entry)) {
diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManagerTest.java
 
b/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManagerTest.java
index dfa4806..41823c1 100644
--- 
a/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManagerTest.java
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/accesscontrol/AclManagerTest.java
@@ -155,7 +155,7 @@ public class AclManagerTest {
     }
 
     private static AccessControlEntry newAcl(boolean isAllow, String 
privileges, String path) {
-        return new AccessControlEntry(isAllow, privileges, new RepoPath(path), 
new RepoPath(PlatformNameFormat.getRepositoryPath(path)));
+        return new AccessControlEntry(isAllow, privileges, new 
RepoPath(PlatformNameFormat.getRepositoryPath(path)));
     }
 
 }
diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/SystemUsersEntryHandlerTest.java
 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/SystemUsersEntryHandlerTest.java
index 0346414..72f88bc 100644
--- 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/SystemUsersEntryHandlerTest.java
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/SystemUsersEntryHandlerTest.java
@@ -98,6 +98,21 @@ public class SystemUsersEntryHandlerTest {
         assertNull(repoinitExtension);
     }
 
+    /**
+     * @see <a 
href="https://issues.apache.org/jira/browse/SLING-9970";>SLING-9970</a>
+     */
+    @Test
+    public void testSystemUserPathIsConvertedToRepositoryPath() throws 
Exception {
+        String path = 
"/jcr_root/home/users/system/_my_feature/_my_user-node/.content.xml";
+        Extension repoinitExtension = parseAndSetRepoinit(path);
+        assertNotNull(repoinitExtension);
+
+        String actual = repoinitExtension.getText();
+        
assertFalse(actual.contains("/jcr_root/home/users/system/_my_feature"));
+        assertFalse(actual.contains("/home/users/system/_my_feature"));
+        assertTrue(actual.contains("/home/users/system/my:feature"));
+    }
+
     private Extension parseAndSetRepoinit(String path) throws Exception {
         Archive archive = mock(Archive.class);
         Entry entry = mock(Entry.class);
diff --git 
a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/_my_feature/_my_user-node/.content.xml
 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/_my_feature/_my_user-node/.content.xml
new file mode 100644
index 0000000..1ede48b
--- /dev/null
+++ 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/home/users/system/_my_feature/_my_user-node/.content.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with this
+ work for additional information regarding copyright ownership. The ASF
+ licenses this file to You under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations under
+ the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0"; xmlns:rep="internal"
+          jcr:primaryType="rep:SystemUser"
+          jcr:uuid="c74065e3-2bdf-3203-b765-200b2f3113ac"
+          rep:authorizableId="SLING-9970"
+          rep:principalName="SLING-9970"/>

Reply via email to