sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject [sling-org-apache-sling-feature-cpconverter] branch multiple-packages-conversion updated: SLING-8390 - Converter not handling serviceusers and acls spread across multiple packages
Date Fri, 03 May 2019 13:20:59 GMT
This is an automated email from the ASF dual-hosted git repository.

simonetripodi pushed a commit to branch multiple-packages-conversion
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git


The following commit(s) were added to refs/heads/multiple-packages-conversion by this push:
     new ff8f0e8  SLING-8390 - Converter not handling serviceusers and acls spread across
multiple packages
ff8f0e8 is described below

commit ff8f0e810d1cb65fea94c83370823c0bcb3da57a
Author: stripodi <stripodi@simos-mbp>
AuthorDate: Fri May 3 15:20:52 2019 +0200

    SLING-8390 - Converter not handling serviceusers and acls spread across
    multiple packages
    
    implemented service user memento from previous conversions
---
 .../ContentPackage2FeatureModelConverter.java      |  1 +
 .../sling/feature/cpconverter/acl/AclManager.java  | 45 ++++++++++++++++------
 .../handlers/RepPolicyEntryHandlerTest.java        |  8 +++-
 3 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
b/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
index 1c25660..6ef0071 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
@@ -316,6 +316,7 @@ public class ContentPackage2FeatureModelConverter {
             }
 
             runmodeMapper.save();
+            aclManager.reset();
         }
     }
 
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/acl/AclManager.java b/src/main/java/org/apache/sling/feature/cpconverter/acl/AclManager.java
index b929520..c4b5402 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/acl/AclManager.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/acl/AclManager.java
@@ -24,6 +24,7 @@ import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -41,6 +42,8 @@ public final class AclManager {
 
     private static final String DEFAULT_TYPE = "sling:Folder";
 
+    private final Set<String> preProvidedSystemUsers = new LinkedHashSet<>();
+
     private final Set<String> systemUsers = new LinkedHashSet<>();
 
     private final Set<String> paths = new TreeSet<String>();
@@ -48,7 +51,7 @@ public final class AclManager {
     private final Map<String, List<Acl>> acls = new HashMap<>();
 
     public boolean addSystemUser(String systemUser) {
-        if (systemUser != null && !systemUser.isEmpty()) {
+        if (systemUser != null && !systemUser.isEmpty() && preProvidedSystemUsers.add(systemUser))
{
             return systemUsers.add(systemUser);
         }
         return false;
@@ -105,23 +108,23 @@ public final class AclManager {
             formatter.format("create path (%s) %s%n", type, path);
         }
 
-        for (String systemUser : systemUsers) {
-            // create then the users
+        // create then the users
 
+        for (String systemUser : systemUsers) {
             formatter.format("create service user %s%n", systemUser);
 
-            // ACL can now be set
+            List<Acl> authorizations = acls.remove(systemUser);
+
+            addAclStatement(formatter, systemUser, authorizations);
+        }
 
-            List<Acl> authorizations = acls.get(systemUser);
-            if (authorizations != null && !authorizations.isEmpty()) {
-                formatter.format("set ACL for %s%n", systemUser);
+        // all the resting ACLs can now be set
 
-                for (Acl authorization : authorizations) {
-                    authorization.addAclStatement(formatter);
-                }
+        for (Entry<String, List<Acl>> currentAcls : acls.entrySet()) {
+            String systemUser = currentAcls.getKey();
+            List<Acl> authorizations = currentAcls.getValue();
 
-                formatter.format("end%n");
-            }
+            addAclStatement(formatter, systemUser, authorizations);
         }
 
         String text = formatter.toString();
@@ -131,4 +134,22 @@ public final class AclManager {
         feature.getExtensions().add(repoInitExtension);
     }
 
+    public void reset() {
+        systemUsers.clear();
+        paths.clear();
+        acls.clear();
+    }
+
+    private void addAclStatement(Formatter formatter, String systemUser, List<Acl>
authorizations) {
+        if (authorizations != null && !authorizations.isEmpty()) {
+            formatter.format("set ACL for %s%n", systemUser);
+
+            for (Acl authorization : authorizations) {
+                authorization.addAclStatement(formatter);
+            }
+
+            formatter.format("end%n");
+        }
+    }
+
 }
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandlerTest.java
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandlerTest.java
index acb57dd..f5d6e43 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandlerTest.java
@@ -107,7 +107,7 @@ public final class RepPolicyEntryHandlerTest {
     }
 
     @Test
-    public void notDeclaredSystemUsersWontHaveAclSettings() throws Exception {
+    public void notDeclaredSystemUsersWillHaveAclSettings() throws Exception {
         Extension repoinitExtension = parseAndSetRepoinit("acs-commons-package-replication-status-event-service",
                                                           "acs-commons-ensure-service-user-service",
                                                           "acs-commons-automatic-package-replicator-service",
@@ -132,6 +132,12 @@ public final class RepPolicyEntryHandlerTest {
                 "create service user acs-commons-on-deploy-scripts-service\n" + 
                 "set ACL for acs-commons-on-deploy-scripts-service\n" + 
                 "allow jcr:read on /asd/public\n" + 
+                "end\n" + 
+                "set ACL for acs-commons-dispatcher-flush-service\n" + 
+                "allow jcr:read,crx:replicate,jcr:removeNode on /asd/public\n" + 
+                "end\n" + 
+                "set ACL for acs-commons-ensure-oak-index-service\n" + 
+                "allow jcr:read,rep:write,rep:indexDefinitionManagement on /asd/public restriction(*/oak:index/*)\n"
+ 
                 "end\n";
         String actual = repoinitExtension.getText();
         assertEquals(expected, actual);


Mime
View raw message