Author: angela
Date: Wed Nov 13 10:23:11 2013
New Revision: 1541452
URL: http://svn.apache.org/r1541452
Log:
OAK-1173 : NPE if TreePermissionImpl if tree does not have a primary type
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/VersionStorageTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java?rev=1541452&r1=1541451&r2=1541452&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java
Wed Nov 13 10:23:11 2013
@@ -157,7 +157,10 @@ final class CompiledPermissionImpl imple
// TODO: OAK-753 decide on where to filter out hidden items.
return TreePermission.ALL;
case TreeTypeProvider.TYPE_VERSION:
- String ntName =
checkNotNull(TreeUtil.getPrimaryTypeName(tree));
+ String ntName = TreeUtil.getPrimaryTypeName(tree);
+ if (ntName == null) {
+ return TreePermission.EMPTY;
+ }
if (VersionConstants.VERSION_STORE_NT_NAMES.contains(ntName)
|| VersionConstants.NT_ACTIVITY.equals(ntName)) {
return new TreePermissionImpl(tree,
TreeTypeProvider.TYPE_VERSION, parentPermission);
} else {
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/VersionStorageTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/VersionStorageTest.java?rev=1541452&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/VersionStorageTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/VersionStorageTest.java
Wed Nov 13 10:23:11 2013
@@ -0,0 +1,148 @@
+/*
+ * 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.security.authorization.evaluation;
+
+import javax.annotation.Nonnull;
+import javax.jcr.security.AccessControlEntry;
+import javax.jcr.security.AccessControlManager;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
+import
org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
+import org.apache.jackrabbit.oak.plugins.version.ReadOnlyVersionManager;
+import org.apache.jackrabbit.oak.plugins.version.VersionConstants;
+import org.apache.jackrabbit.oak.plugins.version.VersionEditorProvider;
+import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
+import org.apache.jackrabbit.oak.util.TreeUtil;
+import org.junit.Test;
+
+import static
org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests related to permission evaluation within the version storage.
+ */
+public class VersionStorageTest extends AbstractOakCoreTest {
+
+ private String vhPath;
+
+ @Override
+ public void before() throws Exception {
+ super.before();
+
+ // make sure the version storage has been setup
+ Tree a = root.getTree("/a");
+ TreeUtil.addMixin(a, JcrConstants.MIX_VERSIONABLE,
root.getTree(NODE_TYPES_PATH), adminSession.getAuthInfo().getUserID());
+ root.commit();
+
+ Tree vs = root.getTree(VersionConstants.VERSION_STORE_PATH);
+ assertTrue(vs.exists());
+ String vhUUID = TreeUtil.getString(a,
VersionConstants.JCR_VERSIONHISTORY);
+ assertNotNull(vhUUID);
+
+ String versionableUuid = TreeUtil.getString(a, JcrConstants.JCR_UUID);
+ vhPath = getVersionHistoryPath(versionableUuid, vs);
+ }
+
+ private String getVersionHistoryPath(String vUUID, final Tree vs) {
+ ReadOnlyVersionManager vMgr = new ReadOnlyVersionManager() {
+ @Nonnull
+ @Override
+ protected Tree getVersionStorage() {
+ return vs;
+ }
+
+ @Nonnull
+ @Override
+ protected Root getWorkspaceRoot() {
+ return root;
+ }
+
+ @Nonnull
+ @Override
+ protected ReadOnlyNodeTypeManager getNodeTypeManager() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ return VersionConstants.VERSION_STORE_PATH + '/' +
vMgr.getVersionHistoryPath(vUUID);
+ }
+
+ @Override
+ public void after() throws Exception {
+ AccessControlManager acMgr = getAccessControlManager(root);
+ JackrabbitAccessControlList acl =
AccessControlUtils.getAccessControlList(acMgr, "/");
+ for (AccessControlEntry ace : acl.getAccessControlEntries()) {
+ if (testPrincipal.equals(ace.getPrincipal())) {
+ acl.removeAccessControlEntry(ace);
+ }
+ }
+ acMgr.setPolicy("/", acl);
+ root.commit();
+ }
+
+ @Override
+ protected Oak withEditors(Oak oak) {
+ return oak.with(new VersionEditorProvider());
+ }
+
+ @Test
+ public void testGetVersionStorage() throws Exception {
+ Tree vs = getTestRoot().getTree(VersionConstants.VERSION_STORE_PATH);
+ assertFalse(vs.exists());
+ }
+
+ @Test
+ public void testGetVersionStorage2() throws Exception {
+ setupPermission("/", testPrincipal, true, PrivilegeConstants.JCR_READ);
+
+ Tree vs = getTestRoot().getTree(VersionConstants.VERSION_STORE_PATH);
+ assertTrue(vs.exists());
+ }
+
+ @Test
+ public void testGetVersionHistory() throws Exception {
+ Tree vs = getTestRoot().getTree(vhPath);
+ assertFalse(vs.exists());
+ }
+
+ @Test
+ public void testGetVersionHistory2() throws Exception {
+ setupPermission("/", testPrincipal, true, PrivilegeConstants.JCR_READ);
+
+ Tree vs = getTestRoot().getTree(vhPath);
+ assertTrue(vs.exists());
+ }
+
+ @Test
+ public void testGetChildrenCountOnVersionStorage() throws Exception {
+ Tree vs = getTestRoot().getTree(VersionConstants.VERSION_STORE_PATH);
+ vs.getChildrenCount(Long.MAX_VALUE);
+ }
+
+ @Test
+ public void testGetChildrenCountOnVersionStorage2() throws Exception {
+ setupPermission("/", testPrincipal, true, PrivilegeConstants.JCR_READ);
+ Tree vs = getTestRoot().getTree(VersionConstants.VERSION_STORE_PATH);
+ vs.getChildrenCount(Long.MAX_VALUE);
+ }
+}
\ No newline at end of file