Author: asanso
Date: Tue Apr 19 06:03:08 2016
New Revision: 1739843

URL: http://svn.apache.org/viewvc?rev=1739843&view=rev
Log:
SLING-5638 - Sling:alias property not working if user does not have read access 
to the root node

Modified:
    
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java

Modified: 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1739843&r1=1739842&r2=1739843&view=diff
==============================================================================
--- 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
 (original)
+++ 
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
 Tue Apr 19 06:03:08 2016
@@ -916,11 +916,23 @@ public class ResourceResolverImpl extend
 
         } else {
 
+            String tokenizedPath = absPath;
+            
             // no direct resource found, so we have to drill down into the
             // resource tree to find a match
             resource = getAbsoluteResourceInternal(null, "/", parameters, 
true);
+            
+            //no read access on / drilling further down
+            //SLING-5638
+            if (resource == null) {
+                resource = getAbsoluteResourceInternal(absPath, parameters, 
true);
+                if (resource != null) {
+                    tokenizedPath = 
tokenizedPath.substring(resource.getPath().length());
+                }
+            }
+            
             final StringBuilder resolutionPath = new StringBuilder();
-            final StringTokenizer tokener = new StringTokenizer(absPath, "/");
+            final StringTokenizer tokener = new StringTokenizer(tokenizedPath, 
"/");
             while (resource != null && tokener.hasMoreTokens()) {
                 final String childNameRaw = tokener.nextToken();
 
@@ -929,7 +941,7 @@ public class ResourceResolverImpl extend
 
                     resource = nextResource;
                     resolutionPath.append("/").append(childNameRaw);
-
+                    
                 } else {
 
                     String childName = null;
@@ -1062,6 +1074,32 @@ public class ResourceResolverImpl extend
         logger.debug("getResourceInternal: Cannot resolve path '{}' to a 
resource", path);
         return null;
     }
+    
+    /**
+     * Creates a resource, traversing bottom up, to the highest readable 
resource.
+     * 
+     */
+    private Resource getAbsoluteResourceInternal(String absPath, final 
Map<String, String> parameters, final boolean isResolved) {
+         
+        if (!absPath.contains("/") || "/".equals(absPath)) {
+            return null;
+        }
+        
+        absPath = absPath.substring(absPath.indexOf("/"));
+        Resource resource = getAbsoluteResourceInternal(null, absPath, 
parameters, isResolved);
+        
+        absPath = absPath.substring(0, absPath.lastIndexOf("/"));
+
+        while (!absPath.equals("")) {
+            Resource r = getAbsoluteResourceInternal(null, absPath, 
parameters, true);
+            
+            if (r != null) {
+                resource = r;
+            }            
+            absPath = absPath.substring(0, absPath.lastIndexOf("/"));
+        }        
+        return resource;
+    }
 
     /**
      * Returns the <code>path</code> as an absolute path. If the path is 
already


Reply via email to