Index: oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAuthorizationConfigurationTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAuthorizationConfigurationTest.java (revision 1863190) +++ oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAuthorizationConfigurationTest.java (date 1563347477000) @@ -170,6 +170,18 @@ assertTrue(pp instanceof PrincipalBasedPermissionProvider); } + @Test + public void testGetPermissionProvider2() throws Exception { + PrincipalBasedAuthorizationConfiguration pbac = new PrincipalBasedAuthorizationConfiguration(); + pbac.bindFilterProvider(getFilterProvider()); + pbac.setSecurityProvider(getSecurityProvider()); + pbac.setRootProvider(getRootProvider()); + + Set principals = ImmutableSet.of(getTestSystemUser().getPrincipal()); + PermissionProvider pp = pbac.getPermissionProvider(root, "wspName", principals); + assertTrue(pp instanceof PrincipalBasedPermissionProvider); + } + @Test public void testGetAccessControlManager() { PrincipalBasedAuthorizationConfiguration pbac = new PrincipalBasedAuthorizationConfiguration(); Index: oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAuthorizationConfigurationWithPrincipalCacheTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAuthorizationConfigurationWithPrincipalCacheTest.java (date 1563347459000) +++ oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAuthorizationConfigurationWithPrincipalCacheTest.java (date 1563347459000) @@ -0,0 +1,28 @@ +/* + * 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.spi.security.authorization.principalbased.impl; + +import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; +import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration; + +public class PrincipalBasedAuthorizationConfigurationWithPrincipalCacheTest extends PrincipalBasedAuthorizationConfigurationTest { + + @Override + protected ConfigurationParameters getSecurityConfigParameters() { + return ConfigurationParameters.of(UserConfiguration.NAME, ConfigurationParameters.of("cacheExpiration", 500)); + } +} \ No newline at end of file Index: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java (revision 1863190) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java (date 1563351825000) @@ -24,6 +24,7 @@ import java.io.InputStream; import java.util.Map; +import org.apache.jackrabbit.oak.api.AuthInfo; import org.apache.jackrabbit.oak.api.Blob; import org.apache.jackrabbit.oak.api.ContentSession; import org.apache.jackrabbit.oak.api.QueryEngine; @@ -47,6 +48,8 @@ public final class ImmutableRoot implements Root, ReadOnly { private final ImmutableTree rootTree; + private final AuthInfo authInfo; + private final String wspName; public ImmutableRoot(@NotNull NodeState rootState) { this(new ImmutableTree(rootState)); @@ -55,8 +58,13 @@ public ImmutableRoot(@NotNull Root root) { if (root instanceof MutableRoot) { rootTree = new ImmutableTree(((MutableRoot) root).getBaseState()); + authInfo = root.getContentSession().getAuthInfo(); + wspName = root.getContentSession().getWorkspaceName(); } else if (root instanceof ImmutableRoot) { - rootTree = ((ImmutableRoot) root).getTree("/"); + ImmutableRoot ir = (ImmutableRoot) root; + rootTree = ir.getTree(PathUtils.ROOT_PATH); + authInfo = ir.authInfo; + wspName = ir.wspName; } else { throw new IllegalArgumentException("Unsupported Root implementation: " + root.getClass()); } @@ -65,6 +73,8 @@ public ImmutableRoot(@NotNull ImmutableTree rootTree) { checkArgument(rootTree.isRoot()); this.rootTree = rootTree; + this.authInfo = AuthInfo.EMPTY; + this.wspName = null; } public static ImmutableRoot getInstance(@NotNull Root root) { @@ -145,7 +155,26 @@ @NotNull @Override public ContentSession getContentSession() { - throw new UnsupportedOperationException(); + return new ContentSession() { + @Override + public @NotNull AuthInfo getAuthInfo() { + return authInfo; + } + + @Override + public String getWorkspaceName() { + return wspName; + } + + @Override + public @NotNull Root getLatestRoot() { + return ImmutableRoot.this; + } + + @Override + public void close() { + } + }; } } Index: oak-it/src/test/java/org/apache/jackrabbit/oak/core/ImmutableRootTest.java =================================================================== --- oak-it/src/test/java/org/apache/jackrabbit/oak/core/ImmutableRootTest.java (revision 1863190) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableRootTest.java (date 1563354246000) @@ -16,42 +16,44 @@ */ package org.apache.jackrabbit.oak.core; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; - -import java.io.ByteArrayInputStream; - -import org.apache.jackrabbit.oak.OakBaseTest; -import org.apache.jackrabbit.oak.api.CommitFailedException; +import org.apache.jackrabbit.oak.AbstractSecurityTest; +import org.apache.jackrabbit.oak.api.AuthInfo; import org.apache.jackrabbit.oak.api.ContentSession; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; -import org.apache.jackrabbit.oak.fixture.NodeStoreFixture; +import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; +import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants; import org.junit.Before; import org.junit.Test; -public class ImmutableRootTest extends OakBaseTest { +import java.io.ByteArrayInputStream; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.fail; + +public class ImmutableRootTest extends AbstractSecurityTest { private ImmutableRoot root; - public ImmutableRootTest(NodeStoreFixture fixture) { - super(fixture); - } - @Before - public void setUp() throws CommitFailedException { - ContentSession session = createContentSession(); + public void before() throws Exception { + super.before(); // Add test content - Root root = session.getLatestRoot(); - Tree tree = root.getTree("/"); - Tree x = tree.addChild("x"); - Tree y = x.addChild("y"); - Tree z = y.addChild("z"); + Root root = adminSession.getLatestRoot(); + Tree tree = root.getTree(PathUtils.ROOT_PATH); + Tree x = TreeUtil.addChild(tree, "x", NodeTypeConstants.NT_OAK_UNSTRUCTURED); + Tree y = TreeUtil.addChild(x, "y", NodeTypeConstants.NT_OAK_UNSTRUCTURED); + Tree z = TreeUtil.addChild(y, "z", NodeTypeConstants.NT_OAK_UNSTRUCTURED); root.commit(); // Acquire a fresh new root to avoid problems from lingering state - this.root = new ImmutableRoot(session.getLatestRoot()); + this.root = new ImmutableRoot(adminSession.getLatestRoot()); } // TODO: add more tests @@ -99,4 +101,28 @@ // success } } + + @Test + public void testGetContentSession() { + ContentSession cs = root.getContentSession(); + assertNotEquals(adminSession, cs); + assertSame(adminSession.getAuthInfo(), cs.getAuthInfo()); + assertEquals(adminSession.getWorkspaceName(), cs.getWorkspaceName()); + } + + @Test + public void testGetContentSessionCreatedFromImmutableRoot() { + ImmutableRoot ir = new ImmutableRoot(root); + ContentSession cs = ir.getContentSession(); + assertSame(root.getContentSession().getAuthInfo(), cs.getAuthInfo()); + assertEquals(root.getContentSession().getWorkspaceName(), cs.getWorkspaceName()); + } + + @Test + public void testGetContentSessionCreatedFromRootTree() { + ImmutableRoot ir = new ImmutableRoot(root.getTree(PathUtils.ROOT_PATH)); + ContentSession cs = ir.getContentSession(); + assertSame(AuthInfo.EMPTY, cs.getAuthInfo()); + assertNull(cs.getWorkspaceName()); + } }