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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1dfb2e1  SLING-9969: UsersEntryHandler and GroupEntryHandler contain 
hardcoded… (#53)
1dfb2e1 is described below

commit 1dfb2e11eac040c1bbd314886e5878a9c801f062
Author: Karl Pauls <[email protected]>
AuthorDate: Tue Jan 19 11:19:21 2021 +0100

    SLING-9969: UsersEntryHandler and GroupEntryHandler contain hardcoded… (#53)
    
    * SLING-9969: UsersEntryHandler and GroupEntryHandler contain hardcoded 
users/groups home path and doesn't include system-rel-path
---
 ...ntentPackage2FeatureModelConverterLauncher.java | 14 +++++++++++-
 .../handlers/AbstractUserEntryHandler.java         | 12 +++++-----
 .../handlers/DefaultEntryHandlersManager.java      |  9 ++++++++
 .../feature/cpconverter/handlers/EntryHandler.java |  3 +++
 .../cpconverter/handlers/GroupEntryHandler.java    | 12 ++++++++--
 .../handlers/RepPolicyEntryHandler.java            |  2 +-
 .../cpconverter/handlers/UsersEntryHandler.java    | 12 ++++++++--
 .../handlers/GroupEntryHandlerTest.java            | 12 ++++++++++
 .../handlers/UsersEntryHandlerTest.java            | 12 ++++++++++
 .../rep:groups/g/V084LLw1ypl2l9G0e28c/.content.xml | 22 ++++++++++++++++++
 .../g/V084LLw1ypl2l9G0e28c/_rep_policy.xml         | 26 ++++++++++++++++++++++
 .../rep:users/a/author/.content.xml                | 23 +++++++++++++++++++
 12 files changed, 147 insertions(+), 12 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncher.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncher.java
index 8e778f6..73dd0c2 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncher.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncher.java
@@ -102,6 +102,9 @@ public final class 
ContentPackage2FeatureModelConverterLauncher implements Runna
     @Option(names = { "--supported-principal-based-path" }, description = 
"Path supported for principal-based access control setup", required = false)
     private String supportedPrincipalBasedPath = null;
 
+    @Option(names = { "--entry-handler-config" }, description = "Config for 
entry handlers that support it (classname:<config-string>", required = false)
+    private List<String> entryHandlerConfigs = null;
+
     @Override
     public void run() {
         if (quiet) {
@@ -145,10 +148,19 @@ public final class 
ContentPackage2FeatureModelConverterLauncher implements Runna
             if (exportsToRegion != null)
                 featuresManager.setExportToAPIRegion(exportsToRegion);
 
+            Map<String, String> entryHandlerConfigsMap = new HashMap<>();
+            if (entryHandlerConfigs != null) {
+                for (String config : entryHandlerConfigs) {
+                    int idx = config.indexOf(':');
+                    if (idx != -1) {
+                        entryHandlerConfigsMap.put(config.substring(0, idx), 
config.substring(idx + 1));
+                    }
+                }
+            }
             ContentPackage2FeatureModelConverter converter = new 
ContentPackage2FeatureModelConverter(strictValidation)
                                                              
.setFeaturesManager(featuresManager)
                                                              
.setBundlesDeployer(new DefaultArtifactsDeployer(artifactsOutputDirectory))
-                                                             
.setEntryHandlersManager(new DefaultEntryHandlersManager())
+                                                             
.setEntryHandlersManager(new 
DefaultEntryHandlersManager(entryHandlerConfigsMap))
                                                              
.setAclManager(new DefaultAclManager(enforcePrincipalBased, 
supportedPrincipalBasedPath))
                                                              
.setEmitter(DefaultPackagesEventsEmitter.open(featureModelsOutputDirectory))
                                                              
.setFailOnMixedPackages(failOnMixedPackages)
diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractUserEntryHandler.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractUserEntryHandler.java
index 26e6a4d..cc2eb1c 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractUserEntryHandler.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractUserEntryHandler.java
@@ -38,14 +38,14 @@ abstract class AbstractUserEntryHandler extends 
AbstractRegexEntryHandler {
         Matcher matcher = getPattern().matcher(path);
         if (matcher.matches()) {
             path = matcher.group(1);
-        }
 
-        RepoPath originalPath = new 
RepoPath(PlatformNameFormat.getRepositoryPath(path));
-        RepoPath intermediatePath = originalPath.getParent();
+            RepoPath originalPath = new 
RepoPath(PlatformNameFormat.getRepositoryPath(path));
+            RepoPath intermediatePath = originalPath.getParent();
 
-        AbstractUserParser parser = createParser(converter, originalPath, 
intermediatePath);
-        try (InputStream input = archive.openInputStream(entry)) {
-            parser.parse(input);
+            AbstractUserParser parser = createParser(converter, originalPath, 
intermediatePath);
+            try (InputStream input = archive.openInputStream(entry)) {
+                parser.parse(input);
+            }
         }
     }
 
diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/DefaultEntryHandlersManager.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/DefaultEntryHandlersManager.java
index 30bb854..af4b375 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/DefaultEntryHandlersManager.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/DefaultEntryHandlersManager.java
@@ -22,14 +22,23 @@ import org.jetbrains.annotations.Nullable;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ServiceLoader;
+import java.util.Collections;
+import java.util.Map;
 
 public class DefaultEntryHandlersManager implements EntryHandlersManager {
 
     private final List<EntryHandler> entryHandlers = new LinkedList<>();
 
     public DefaultEntryHandlersManager() {
+        this(Collections.emptyMap());
+    }
+
+    public DefaultEntryHandlersManager(Map<String, String> configs) {
         ServiceLoader<EntryHandler> entryHandlersLoader = 
ServiceLoader.load(EntryHandler.class);
         for (EntryHandler entryHandler : entryHandlersLoader) {
+            if (configs.containsKey(entryHandler.getClass().getName())) {
+                entryHandler = 
entryHandler.withConfig(configs.get(entryHandler.getClass().getName()));
+            }
             addEntryHandler(entryHandler);
         }
     }
diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/EntryHandler.java 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/EntryHandler.java
index 1160ad3..6c64747 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/EntryHandler.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/EntryHandler.java
@@ -27,4 +27,7 @@ public interface EntryHandler {
 
     void handle(@NotNull String path, @NotNull Archive archive, @NotNull Entry 
entry, @NotNull ContentPackage2FeatureModelConverter converter) throws 
Exception;
 
+    default EntryHandler withConfig(@NotNull String config) {
+        return this;
+    }
 }
diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/GroupEntryHandler.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/GroupEntryHandler.java
index afea198..7d1b2b2 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/GroupEntryHandler.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/GroupEntryHandler.java
@@ -24,8 +24,16 @@ import org.jetbrains.annotations.NotNull;
 public final class GroupEntryHandler extends AbstractUserEntryHandler {
 
     public GroupEntryHandler() {
-        // FIXME: SLING-9969
-        super("/jcr_root(/home/groups.*/)\\.content.xml");
+        this("/jcr_root(/home/groups.*/)\\.content.xml");
+    }
+
+    public GroupEntryHandler(@NotNull String regex) {
+        super(regex);
+    }
+
+    @Override
+    public EntryHandler withConfig(@NotNull String config) {
+        return new GroupEntryHandler(config);
     }
 
     @Override
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 0cc3296..fb5cea6 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
@@ -33,7 +33,7 @@ import static 
org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 public class RepPolicyEntryHandler extends AbstractPolicyEntryHandler {
 
     public RepPolicyEntryHandler() {
-        super("/jcr_root(.*/)_rep_policy.xml");
+        this("/jcr_root(.*/)_rep_policy.xml");
     }
 
     RepPolicyEntryHandler(@NotNull String regex) {
diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/UsersEntryHandler.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/UsersEntryHandler.java
index 6773c4d..3291415 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/UsersEntryHandler.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/UsersEntryHandler.java
@@ -25,8 +25,16 @@ import org.jetbrains.annotations.NotNull;
 public final class UsersEntryHandler extends AbstractUserEntryHandler {
 
     public UsersEntryHandler() {
-        // FIXME: SLING-9969
-        super("/jcr_root(/home/users/.*/)\\.content.xml");
+        this("/jcr_root(/home/users/.*/)\\.content.xml");
+    }
+
+    public UsersEntryHandler(@NotNull String regex) {
+        super(regex);
+    }
+
+    @Override
+    public EntryHandler withConfig(@NotNull String config) {
+        return new UsersEntryHandler(config);
     }
 
     @Override
diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/GroupEntryHandlerTest.java
 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/GroupEntryHandlerTest.java
index 97f2650..305d4cf 100644
--- 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/GroupEntryHandlerTest.java
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/GroupEntryHandlerTest.java
@@ -70,4 +70,16 @@ public class GroupEntryHandlerTest {
         TestUtils.createRepoInitExtension(handler, aclManager, path, 
getClass().getResourceAsStream(path.substring(1)));
         verify(aclManager, never()).addGroup(any(Group.class));
     }
+
+    @Test
+    public void parseGroupWithConfig() throws Exception {
+        String path = 
"/jcr_root/rep:security/rep:authorizables/rep:groups/g/V084LLw1ypl2l9G0e28c/.content.xml";
+        AclManager aclManager = mock(AclManager.class);
+
+        TestUtils.createRepoInitExtension(handler, aclManager, path, 
getClass().getResourceAsStream(path.substring(1)));
+        verify(aclManager, never()).addGroup(any(Group.class));
+
+        
TestUtils.createRepoInitExtension(handler.withConfig("/jcr_root(/rep:security/rep:authorizables/rep:groups.*/)\\.content.xml"),
 aclManager, path, getClass().getResourceAsStream(path.substring(1)));
+        verify(aclManager, times(1)).addGroup(any(Group.class));
+    }
 }
diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/UsersEntryHandlerTest.java
 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/UsersEntryHandlerTest.java
index 914a51c..283d63f 100644
--- 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/UsersEntryHandlerTest.java
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/UsersEntryHandlerTest.java
@@ -118,6 +118,18 @@ public class UsersEntryHandlerTest {
         verify(aclManager, never()).addSystemUser(any(SystemUser.class));
     }
 
+    @Test
+    public void parseUserWithConfig() throws Exception {
+        String path = 
"/jcr_root/rep:security/rep:authorizables/rep:users/a/author/.content.xml";
+        AclManager aclManager = mock(AclManager.class);
+
+        TestUtils.createRepoInitExtension(usersEntryHandler, aclManager, path, 
getClass().getResourceAsStream(path.substring(1)));
+        verify(aclManager, never()).addUser(any(User.class));
+
+        
TestUtils.createRepoInitExtension(usersEntryHandler.withConfig("/jcr_root(/rep:security/rep:authorizables/rep:users.*/)\\.content.xml"),
 aclManager, path, getClass().getResourceAsStream(path.substring(1)));
+        verify(aclManager, times(1)).addUser(any(User.class));
+    }
+
     private Extension parseAndSetRepoinit(String path) throws Exception {
         return TestUtils.createRepoInitExtension(usersEntryHandler, new 
DefaultAclManager(), path, getClass().getResourceAsStream(path.substring(1)));
     }
diff --git 
a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/rep:security/rep:authorizables/rep:groups/g/V084LLw1ypl2l9G0e28c/.content.xml
 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/rep:security/rep:authorizables/rep:groups/g/V084LLw1ypl2l9G0e28c/.content.xml
new file mode 100644
index 0000000..307f81b
--- /dev/null
+++ 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/rep:security/rep:authorizables/rep:groups/g/V084LLw1ypl2l9G0e28c/.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:Group"
+          jcr:uuid="62a34b2f-0897-32be-909e-a9ae27b85688"
+          rep:authorizableId="testgroup2"
+          rep:principalName="testgroup2"/>
diff --git 
a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/rep:security/rep:authorizables/rep:groups/g/V084LLw1ypl2l9G0e28c/_rep_policy.xml
 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/rep:security/rep:authorizables/rep:groups/g/V084LLw1ypl2l9G0e28c/_rep_policy.xml
new file mode 100644
index 0000000..942b0a3
--- /dev/null
+++ 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/rep:security/rep:authorizables/rep:groups/g/V084LLw1ypl2l9G0e28c/_rep_policy.xml
@@ -0,0 +1,26 @@
+<?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:ACL">
+    <!-- entry not to be converted to repo-init statement -->
+    <allow1
+            jcr:primaryType="rep:GrantACE"
+            rep:principalName="testgroup2"
+            rep:privileges="{Name}[jcr:read]">
+    </allow1>
+</jcr:root>
diff --git 
a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/rep:security/rep:authorizables/rep:users/a/author/.content.xml
 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/rep:security/rep:authorizables/rep:users/a/author/.content.xml
new file mode 100644
index 0000000..4f64da2
--- /dev/null
+++ 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/rep:security/rep:authorizables/rep:users/a/author/.content.xml
@@ -0,0 +1,23 @@
+<?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:mixinTypes="[rep:AccessControllable]"
+          jcr:primaryType="rep:User"
+          jcr:uuid="02bd92fa-a38a-3a6c-80ea-75e59937a1ef"
+          rep:authorizableId="author"
+          rep:principalName="author"/>
\ No newline at end of file

Reply via email to