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/09/02 07:31:59 UTC

[sling-org-apache-sling-feature-cpconverter] 01/01: SLING-10786 : DefaultAclManager - sonar finding

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

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

commit 74635e76a161163b6f95a5ae69ab372c0d0c18c2
Author: angela <an...@adobe.com>
AuthorDate: Thu Sep 2 09:31:36 2021 +0200

    SLING-10786 : DefaultAclManager - sonar finding
---
 .../accesscontrol/DefaultAclManager.java           | 38 +++++++++++++---------
 1 file changed, 22 insertions(+), 16 deletions(-)

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 c6fed64..89ffe92 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
@@ -422,10 +422,29 @@ public class DefaultAclManager implements AclManager, EnforceInfo {
     }
 
     protected @Nullable CreatePath getCreatePath(@NotNull RepoPath path, @NotNull List<VaultPackageAssembler> packageAssemblers) {
+        if (path.getParent() == null) {
+            log.debug("Omit create path statement for path '{}'", path);
+            return null;
+        }
+        
+        CreatePath cp = new CreatePath(null);
+        boolean foundType = processSegments(path, packageAssemblers, cp);
+        
+        if (!foundType && isBelowUserRoot(path)) {
+            // if no type information has been detected, don't issue a 'create path' statement for nodes below the 
+            // user-root 
+            log.warn("Failed to extract primary type information for node at path '{}'", path);
+            return null;
+        } else {
+            // assume that primary type information is present or can be extracted from default primary type definition 
+            // of the the top-level nodes (i.e. their effective node type definition).
+            return cp;
+        }
+    }
+    
+    private static boolean processSegments(@NotNull RepoPath path, @NotNull List<VaultPackageAssembler> packageAssemblers, @NotNull CreatePath cp) {
         String platformPath = "";
         boolean foundType = false;
-
-        CreatePath cp = new CreatePath(null);
         for (String part : path.getSegments()) {
             String platformname = PlatformNameFormat.getPlatformName(part);
             platformPath += platformPath.isEmpty() ? platformname : "/" + platformname;
@@ -444,20 +463,7 @@ public class DefaultAclManager implements AclManager, EnforceInfo {
                 cp.addSegment(part, null);
             }
         }
-        
-        if (!foundType && isBelowUserRoot(path)) {
-            // if no type information has been detected, don't issue a 'create path' statement for nodes below the 
-            // user-root 
-            log.warn("Failed to extract primary type information for node at path '{}'", path);
-            return null;
-        } else if (path.getParent() == null) {
-            log.debug("Omit create path statement for path '{}'", path);
-            return null;
-        } else {
-            // assume that primary type information is present or can be extracted from default primary type definition 
-            // of the the top-level nodes (i.e. their effective node type definition).
-            return cp;
-        }
+        return foundType;
     }
 
     private static boolean addSegment(@NotNull CreatePath cp, @NotNull String part, @NotNull File currentContent) {