[ 
https://issues.apache.org/jira/browse/JCR-4015?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15467583#comment-15467583
 ] 

Carsten Ziegeler commented on JCR-4015:
---------------------------------------

[~reschke] Proposed patch
{code}
Index: src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
===================================================================
--- src/main/java/org/apache/jackrabbit/commons/JcrUtils.java   (Revision 
1759423)
+++ src/main/java/org/apache/jackrabbit/commons/JcrUtils.java   (Arbeitskopie)
@@ -1449,8 +1449,22 @@
             // path denotes root node
             return session.getRootNode();
         }
+        // find deepest existing parent node
+        String path = absolutePath;
+        String existingPath = null;
+        int currentIndex = path.lastIndexOf('/');
+        while (currentIndex > 0) {
+            path = path.substring(0, currentIndex);
+            // break when first existing parent is found
+            if (session.nodeExists(path)) {
+                existingPath = path;
+                break;
+            }
+            currentIndex = path.lastIndexOf('/');
+        }
         // create path relative to the root node
-        return getOrCreateByPath(session.getRootNode(), 
absolutePath.substring(1),
+        return getOrCreateByPath(existingPath == null ? session.getRootNode() 
: session.getNode(existingPath),
+                absolutePath.substring(currentIndex + 1),
                 createUniqueLeaf, intermediateNodeType, nodeType, autoSave);
     }
 {code}

> CLONE - jackrabbit-jcr-commons JcrUtils.getOrCreateByPath fails if session is 
> not allowed to read root
> ------------------------------------------------------------------------------------------------------
>
>                 Key: JCR-4015
>                 URL: https://issues.apache.org/jira/browse/JCR-4015
>             Project: Jackrabbit Content Repository
>          Issue Type: Bug
>          Components: jackrabbit-jcr-commons
>    Affects Versions: 2.4.5, 2.6.5, 2.8.1, 2.10.3, 2.12.2
>            Reporter: Carsten Ziegeler
>
> JcrUtils.getOrCreateByPath  starts to try to find the node from the root down 
> to the specified path, therefore if the current session has not access to 
> "/", it fails. JcrUtils.getOrCreateByPath must try the longest path first and 
> then reduce it until it finds an accessible node. So for example if the input 
> is "/a/b/c" instead of testing for "/", "/a", "/a/b" .. it should test 
> /a/b/c, /a/b, /a and then /



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to