jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1440930 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ oak-core/src/main/java/org/a...
Date Thu, 31 Jan 2013 12:31:33 GMT
Author: mduerig
Date: Thu Jan 31 12:31:33 2013
New Revision: 1440930

URL: http://svn.apache.org/viewvc?rev=1440930&view=rev
Log:
OAK-598: TreeLocation#NULL allows to reveal the existence of items that are not accessible

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/NullLocation.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ReadOnlyVersionManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/Permissions.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/LocationUtil.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java?rev=1440930&r1=1440929&r2=1440930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
Thu Jan 31 12:31:33 2013
@@ -37,69 +37,6 @@ import org.apache.jackrabbit.oak.api.Tre
 public interface TreeLocation {
 
     /**
-     * This {@code TreeLocation} refers to an invalid location in a tree. That is
-     * to a location where no item resides.
-     */
-    TreeLocation NULL = new TreeLocation() {
-
-        /**
-         * @return  {@code NULL}
-         */
-        @Override
-        public TreeLocation getParent() {
-            return NULL;
-        }
-
-        /**
-         * @return  {@code NULL}
-         */
-        @Override
-        public TreeLocation getChild(String relPath) {
-            return NULL;
-        }
-
-        /**
-         * @return  {@code null}
-         */
-        @Override
-        public String getPath() {
-            return null;
-        }
-
-        /**
-         * @return Always {@code false}.
-         */
-        @Override
-        public boolean remove() {
-            return false;
-        }
-
-        /**
-         * @return  {@code null}
-         */
-        @Override
-        public Tree getTree() {
-            return null;
-        }
-
-        /**
-         * @return  {@code null}
-         */
-        @Override
-        public PropertyState getProperty() {
-            return null;
-        }
-
-        /**
-         * @return  {@code null}
-         */
-        @Override
-        public Status getStatus() {
-            return null;
-        }
-    };
-
-    /**
      * Navigate to the parent
      * @return  a {@code TreeLocation} for the parent of this location.
      */
@@ -116,6 +53,15 @@ public interface TreeLocation {
     TreeLocation getChild(String relPath);
 
     /**
+     * Determine whether the underlying {@link org.apache.jackrabbit.oak.api.Tree} or
+     * {@link org.apache.jackrabbit.oak.api.PropertyState} for this {@code TreeLocation}
+     * is available.
+     * @return  {@code true} if either {@link #getTree()} or {@link #getParent()} is non
{@code null}.
+     * {@code false} otherwise.
+     */
+    boolean exists();
+
+    /**
      * Get the underlying {@link org.apache.jackrabbit.oak.api.Tree} for this {@code TreeLocation}.
      * @return  underlying {@code Tree} instance or {@code null} if not available.
      */

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java?rev=1440930&r1=1440929&r2=1440930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
Thu Jan 31 12:31:33 2013
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.core;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Tree.Status;
 import org.apache.jackrabbit.oak.api.TreeLocation;
 
 import static com.google.common.base.Preconditions.checkNotNull;
@@ -34,6 +35,12 @@ abstract class AbstractNodeLocation<T ex
     }
 
     @Override
+    public boolean exists() {
+        Status status = getStatus();
+        return status != null && status != Status.REMOVED && getTree() !=
null;
+    }
+
+    @Override
     public String getPath() {
         return tree.getPath();
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java?rev=1440930&r1=1440929&r2=1440930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java
Thu Jan 31 12:31:33 2013
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.core;
 
 import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Tree.Status;
 import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 
@@ -42,7 +43,13 @@ abstract class AbstractPropertyLocation<
 
     @Override
     public TreeLocation getChild(String relPath) {
-        return TreeLocation.NULL;
+        return NullLocation.NULL;
+    }
+
+    @Override
+    public boolean exists() {
+        Status status = getStatus();
+        return status != null && status != Status.REMOVED && getProperty()
!= null;
     }
 
     @Override

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/NullLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/NullLocation.java?rev=1440930&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/NullLocation.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/NullLocation.java
Thu Jan 31 12:31:33 2013
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+package org.apache.jackrabbit.oak.core;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Tree.Status;
+import org.apache.jackrabbit.oak.api.TreeLocation;
+
+/**
+ * This {@code TreeLocation} refers to an invalid location in a tree. That is
+ * to a location where no item resides.
+ */
+final class NullLocation implements TreeLocation {
+    static final TreeLocation NULL = new NullLocation();
+
+    private NullLocation() {
+    }
+
+    /**
+     * @return  {@code NULL}
+     */
+    @Override
+    public TreeLocation getParent() {
+        return NULL;
+    }
+
+    /**
+     * @return  {@code NULL}
+     */
+    @Override
+    public TreeLocation getChild(String relPath) {
+        return NULL;
+    }
+
+    /**
+     * @return {@code false}
+     */
+    @Override
+    public boolean exists() {
+        return false;
+    }
+
+    /**
+     * @return  {@code null}
+     */
+    @Override
+    public String getPath() {
+        return null;
+    }
+
+    /**
+     * @return Always {@code false}.
+     */
+    @Override
+    public boolean remove() {
+        return false;
+    }
+
+    /**
+     * @return  {@code null}
+     */
+    @Override
+    public Tree getTree() {
+        return null;
+    }
+
+    /**
+     * @return  {@code null}
+     */
+    @Override
+    public PropertyState getProperty() {
+        return null;
+    }
+
+    /**
+     * @return  {@code null}
+     */
+    @Override
+    public Status getStatus() {
+        return null;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/NullLocation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/NullLocation.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java?rev=1440930&r1=1440929&r2=1440930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
Thu Jan 31 12:31:33 2013
@@ -253,7 +253,7 @@ public class ReadOnlyTree implements Tre
         @Override
         public TreeLocation getParent() {
             return tree.parent == null
-                    ? TreeLocation.NULL
+                    ? NullLocation.NULL
                     : new NodeLocation(tree.parent);
         }
 
@@ -269,7 +269,7 @@ public class ReadOnlyTree implements Tre
             for (String name : PathUtils.elements(parentPath)) {
                 child = child.getChild(name);
                 if (child == null) {
-                    return TreeLocation.NULL;
+                    return NullLocation.NULL;
                 }
             }
 
@@ -280,7 +280,7 @@ public class ReadOnlyTree implements Tre
             } else {
                 child = child.getChild(name);
                 return child == null
-                        ? TreeLocation.NULL
+                        ? NullLocation.NULL
                         : new NodeLocation(child);
             }
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1440930&r1=1440929&r2=1440930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Thu Jan 31 12:31:33 2013
@@ -593,7 +593,7 @@ public class TreeImpl implements Tree {
         @Override
         public TreeLocation getParent() {
             return tree.parent == null
-                    ? TreeLocation.NULL
+                    ? NullLocation.NULL
                     : new NodeLocation(tree.parent);
         }
 
@@ -609,7 +609,7 @@ public class TreeImpl implements Tree {
             for (String name : PathUtils.elements(parentPath)) {
                 child = child.internalGetChild(name);
                 if (child == null) {
-                    return TreeLocation.NULL;
+                    return NullLocation.NULL;
                 }
             }
 
@@ -620,7 +620,7 @@ public class TreeImpl implements Tree {
             } else {
                 child = child.internalGetChild(name);
                 return child == null
-                        ? TreeLocation.NULL
+                        ? NullLocation.NULL
                         : new NodeLocation(child);
             }
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ReadOnlyVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ReadOnlyVersionManager.java?rev=1440930&r1=1440929&r2=1440930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ReadOnlyVersionManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ReadOnlyVersionManager.java
Thu Jan 31 12:31:33 2013
@@ -177,6 +177,8 @@ public abstract class ReadOnlyVersionMan
             PropertyState p = t.getProperty(VersionConstants.JCR_ISCHECKEDOUT);
             if (p != null) {
                 return p.getValue(Type.BOOLEAN);
+            } else if (t.isRoot()) {
+                return true;
             }
         } else {
             // FIXME: this actually means access to the tree is restricted
@@ -187,12 +189,7 @@ public abstract class ReadOnlyVersionMan
             // it is in fact read-only because of a checked-in ancestor.
         }
         // otherwise return checkedOut status of parent
-        if (location.getParent() == TreeLocation.NULL) {
-            // root tree
-            return true;
-        } else {
-            return isCheckedOut(location.getParent());
-        }
+        return isCheckedOut(location.getParent());
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/Permissions.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/Permissions.java?rev=1440930&r1=1440929&r2=1440930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/Permissions.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/Permissions.java
Thu Jan 31 12:31:33 2013
@@ -169,7 +169,7 @@ public final class Permissions {
             permissions |= ADD_PROPERTY | MODIFY_PROPERTY;
         }
         if (s.remove(Session.ACTION_REMOVE)) {
-            if (location == TreeLocation.NULL) {
+            if (!location.exists()) {
                 permissions |= REMOVE;
             } else if (location.getProperty() == null) {
                 permissions |= REMOVE_NODE;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/LocationUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/LocationUtil.java?rev=1440930&r1=1440929&r2=1440930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/LocationUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/LocationUtil.java
Thu Jan 31 12:31:33 2013
@@ -36,7 +36,7 @@ public final class LocationUtil {
     public static TreeLocation getTreeLocation(TreeLocation parentLocation, String relativePath)
{
         TreeLocation targetLocation = parentLocation;
         String[] segments = Text.explode(relativePath, '/', false);
-        for (int i = 0; i < segments.length && targetLocation != TreeLocation.NULL;
i++) {
+        for (int i = 0; i < segments.length && targetLocation.exists(); i++) {
             String segment = segments[i];
             if (PathUtils.denotesCurrent(segment)) {
                 continue;

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java?rev=1440930&r1=1440929&r2=1440930&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
Thu Jan 31 12:31:33 2013
@@ -117,7 +117,7 @@ public abstract class ItemDelegate {
     @Nonnull
     public TreeLocation getLocation() throws InvalidItemStateException {
         TreeLocation location = getLocationOrNull();
-        if (location == TreeLocation.NULL) {
+        if (!location.exists()) {
             throw new InvalidItemStateException("Item is stale");
         }
         return location;
@@ -135,11 +135,11 @@ public abstract class ItemDelegate {
      * The underlying {@link org.apache.jackrabbit.oak.api.TreeLocation} of this item.
      * The location is only re-resolved when the revision of this item does not match
      * the revision of the session.
-     * @return  tree location of the underlying item or {@link TreeLocation#NULL} if stale.
+     * @return  tree location of the underlying item or {@link org.apache.jackrabbit.oak.core.NullLocation#NULL}
if stale.
      */
     @Nonnull
     private synchronized TreeLocation getLocationOrNull() {
-        if (location != TreeLocation.NULL && sessionDelegate.getRevision() != revision)
{
+        if (location.exists() && sessionDelegate.getRevision() != revision) {
             location = sessionDelegate.getLocation(location.getPath());
             revision = sessionDelegate.getRevision();
         }



Mime
View raw message