### Eclipse Workspace Patch 1.0 #P oak Index: oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplFuzzIT.java =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplFuzzIT.java (revision 1507963) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplFuzzIT.java (working copy) @@ -73,12 +73,12 @@ MicroKernel mk1 = new MicroKernelImpl("./target/mk1/" + random.nextInt()); store1 = new KernelNodeStore(mk1); mk1.commit("", "+\"/root\":{}", mk1.getHeadRevision(), ""); - root1 = new RootImpl(store1); + root1 = new SystemRoot(store1); MicroKernel mk2 = new MicroKernelImpl("./target/mk2/" + random.nextInt()); store2 = new KernelNodeStore(mk2); mk2.commit("", "+\"/root\":{}", mk2.getHeadRevision(), ""); - root2 = new RootImpl(store2); + root2 = new SystemRoot(store2); } @Test Index: oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java (revision 1507963) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java (working copy) @@ -16,24 +16,19 @@ */ package org.apache.jackrabbit.oak.security.user; -import java.security.Principal; -import java.util.Set; + import javax.annotation.Nonnull; import javax.jcr.RepositoryException; - import com.google.common.base.Strings; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.user.UserManager; -import org.apache.jackrabbit.oak.api.AuthInfo; import org.apache.jackrabbit.oak.api.CommitFailedException; -import org.apache.jackrabbit.oak.api.ContentSession; import org.apache.jackrabbit.oak.api.Root; -import org.apache.jackrabbit.oak.core.RootImpl; +import org.apache.jackrabbit.oak.core.SystemRoot; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.index.IndexConstants; import org.apache.jackrabbit.oak.plugins.index.IndexUtils; import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore; -import org.apache.jackrabbit.oak.security.authentication.SystemSubject; import org.apache.jackrabbit.oak.spi.commit.CommitHook; import org.apache.jackrabbit.oak.spi.commit.EmptyHook; import org.apache.jackrabbit.oak.spi.commit.PostCommitHook; @@ -44,14 +39,12 @@ import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration; import org.apache.jackrabbit.oak.spi.security.user.UserConstants; import org.apache.jackrabbit.oak.spi.state.NodeState; -import org.apache.jackrabbit.oak.spi.state.NodeStore; import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch; import org.apache.jackrabbit.oak.util.NodeUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; /** * Creates initial set of users to be present in a given workspace. This @@ -105,7 +98,7 @@ throw new RuntimeException(e); } - Root root = new SystemRootImpl(store, commitHook, workspaceName, securityProvider, indexProvider); + Root root = new SystemRoot(store, commitHook, workspaceName, securityProvider, indexProvider); UserConfiguration userConfiguration = securityProvider.getConfiguration(UserConfiguration.class); UserManager userManager = userConfiguration.getUserManager(root, NamePathMapper.DEFAULT); @@ -149,71 +142,4 @@ } return store.getRoot(); } - - //--------------------------------------------------------< inner class >--- - - private class SystemRootImpl extends RootImpl { - - private SystemRootImpl(NodeStore store, CommitHook hook, - String workspaceName, - SecurityProvider securityProvider, - QueryIndexProvider indexProvider) { - super(store, hook, PostCommitHook.EMPTY, workspaceName, SystemSubject.INSTANCE, - securityProvider, indexProvider); - } - - @Override - public ContentSession getContentSession() { - return new ContentSession() { - - private volatile boolean live = true; - - private void checkLive() { - checkState(live, "This session has been closed"); - } - - @Override - public void close() { - live = false; - } - - @Override - public String getWorkspaceName() { - return SystemRootImpl.this.getWorkspaceName(); - } - - @Override - public Root getLatestRoot() { - checkLive(); - return SystemRootImpl.this; - } - - @Override - public AuthInfo getAuthInfo() { - return new AuthInfo() { - - @Override - public String getUserID() { - return null; - } - - @Override - public Set getPrincipals() { - return SystemSubject.INSTANCE.getPrincipals(); - } - - @Override - public String[] getAttributeNames() { - return new String[]{}; - } - - @Override - public Object getAttribute(String attributeName) { - return null; - } - }; - } - }; - } - } } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java (revision 1507963) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java (working copy) @@ -153,18 +153,7 @@ secureBuilder = new SecureNodeBuilder(builder, getPermissionProvider(), getAcContext()); rootTree = new MutableTree(this, secureBuilder, lastMove); } - - // TODO: review if these constructors really make sense and cannot be replaced. - public RootImpl(NodeStore store) { - this(store, EmptyHook.INSTANCE); - } - - public RootImpl(NodeStore store, CommitHook hook) { - // FIXME: define proper default or pass workspace name with the constructor - this(store, hook, PostCommitHook.EMPTY, Oak.DEFAULT_WORKSPACE_NAME, SystemSubject.INSTANCE, - new OpenSecurityProvider(), new CompositeQueryIndexProvider()); - } - + /** * Called whenever a method on this instance or on any {@code Tree} instance * obtained from this {@code Root} is called. This default implementation Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java (revision 1507963) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java (working copy) @@ -21,7 +21,7 @@ import org.apache.felix.scr.annotations.Service; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.Type; -import org.apache.jackrabbit.oak.core.RootImpl; +import org.apache.jackrabbit.oak.core.SystemRoot; import org.apache.jackrabbit.oak.plugins.index.IndexConstants; import org.apache.jackrabbit.oak.plugins.index.IndexUtils; import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore; @@ -81,7 +81,7 @@ } catch (CommitFailedException e) { throw new RuntimeException(e); } - BuiltInNodeTypes.register(new RootImpl(store, new EditorHook(new RegistrationEditorProvider()))); + BuiltInNodeTypes.register(new SystemRoot(store, new EditorHook(new RegistrationEditorProvider()))); return store.getRoot(); } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/core/SystemRoot.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/core/SystemRoot.java (revision 0) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/core/SystemRoot.java (revision 0) @@ -0,0 +1,84 @@ +/* + * 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 java.io.IOException; +import org.apache.jackrabbit.oak.Oak; +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.security.authentication.SystemSubject; +import org.apache.jackrabbit.oak.spi.commit.CommitHook; +import org.apache.jackrabbit.oak.spi.commit.EmptyHook; +import org.apache.jackrabbit.oak.spi.commit.PostCommitHook; +import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider; +import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider; +import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider; +import org.apache.jackrabbit.oak.spi.security.SecurityProvider; +import org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl; +import org.apache.jackrabbit.oak.spi.state.NodeStore; + +/** + * Internal extension of the {@link RootImpl} to be used + * when an usage of the system internal subject is needed. + * + */ +public class SystemRoot extends RootImpl { + + public SystemRoot(NodeStore store, CommitHook hook, String workspaceName, + SecurityProvider securityProvider, QueryIndexProvider indexProvider) { + super(store, hook, PostCommitHook.EMPTY, workspaceName, + SystemSubject.INSTANCE, securityProvider, indexProvider); + } + + public SystemRoot(NodeStore store) { + this(store, EmptyHook.INSTANCE); + } + + public SystemRoot(NodeStore store, CommitHook hook) { + // FIXME: define proper default or pass workspace name with the + // constructor + this(store, hook, Oak.DEFAULT_WORKSPACE_NAME, + new OpenSecurityProvider(), new CompositeQueryIndexProvider()); + } + + @Override + public ContentSession getContentSession() { + return new ContentSession() { + + @Override + public void close() throws IOException { + } + + @Override + public String getWorkspaceName() { + return SystemRoot.this.getWorkspaceName(); + } + + @Override + public Root getLatestRoot() { + throw new UnsupportedOperationException(); + } + + @Override + public AuthInfo getAuthInfo() { + return new AuthInfoImpl(null, null, SystemSubject.INSTANCE.getPrincipals()); + } + }; + } + +} Index: oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeInitializer.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeInitializer.java (revision 1507963) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeInitializer.java (working copy) @@ -22,7 +22,7 @@ import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.Type; -import org.apache.jackrabbit.oak.core.RootImpl; +import org.apache.jackrabbit.oak.core.SystemRoot; import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore; import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants; import org.apache.jackrabbit.oak.spi.commit.EmptyHook; @@ -67,7 +67,7 @@ } try { - new PrivilegeDefinitionWriter(new RootImpl(store)).writeBuiltInDefinitions(); + new PrivilegeDefinitionWriter(new SystemRoot(store)).writeBuiltInDefinitions(); } catch (RepositoryException e) { log.error("Failed to register built-in privileges", e); throw new RuntimeException(e);