You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2013/07/23 15:24:20 UTC
svn commit: r1506035 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak:
core/RootImpl.java security/user/UserInitializer.java
Author: angela
Date: Tue Jul 23 13:24:20 2013
New Revision: 1506035
URL: http://svn.apache.org/r1506035
Log:
OAK-923 : Runtime exception while creating a group (part 1 of patch provided by antonio sanso addressing TODO in UserInitializer, slightly as commented in the issue)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1506035&r1=1506034&r2=1506035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java Tue Jul 23 13:24:20 2013
@@ -18,17 +18,12 @@
*/
package org.apache.jackrabbit.oak.core;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
-import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
-
import java.io.IOException;
import java.io.InputStream;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-
import javax.annotation.Nonnull;
import javax.security.auth.Subject;
@@ -65,6 +60,10 @@ import org.apache.jackrabbit.oak.spi.sta
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
+import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
+
public class RootImpl implements Root {
/**
@@ -104,7 +103,9 @@ public class RootImpl implements Root {
*/
private NodeBuilder builder;
- /** Sentinel for the next move operation to take place on the this root */
+ /**
+ * Sentinel for the next move operation to take place on the this root
+ */
private Move lastMove = new Move();
/**
@@ -169,13 +170,17 @@ public class RootImpl implements Root {
}
+ protected String getWorkspaceName() {
+ return workspaceName;
+ }
+
//---------------------------------------------------------------< Root >---
-
- @Override
- public ContentSession getContentSession() {
- throw new UnsupportedOperationException();
- }
-
+
+ @Override
+ public ContentSession getContentSession() {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public boolean move(String sourcePath, String destPath) {
if (PathUtils.isAncestor(sourcePath, destPath)) {
@@ -458,22 +463,30 @@ public class RootImpl implements Root {
* The last entry in the list is always an empty slot to be filled in by calling
* {@code setMove()}. This fills the slot with the source and destination of the move
* and links this move to the next one which will be the new empty slot.
- *
+ * <p/>
* Moves can be applied to {@code MutableTree} instances by calling {@code apply()},
* which will execute all moves in the list on the passed tree instance
*/
class Move {
- /** source path */
+ /**
+ * source path
+ */
private String source;
- /** Parent tree of the destination */
+ /**
+ * Parent tree of the destination
+ */
private MutableTree destParent;
- /** Name at the destination */
+ /**
+ * Name at the destination
+ */
private String destName;
- /** Pointer to the next move. {@code null} if this is the last, empty slot */
+ /**
+ * Pointer to the next move. {@code null} if this is the last, empty slot
+ */
private Move next;
/**
@@ -504,8 +517,8 @@ public class RootImpl implements Root {
@Override
public String toString() {
return source == null
- ? "NIL"
- : '>' + source + ':' + PathUtils.concat(destParent.getPathInternal(), destName);
+ ? "NIL"
+ : '>' + source + ':' + PathUtils.concat(destParent.getPathInternal(), destName);
}
}
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java?rev=1506035&r1=1506034&r2=1506035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java Tue Jul 23 13:24:20 2013
@@ -16,15 +16,17 @@
*/
package org.apache.jackrabbit.oak.security.user;
-import static com.google.common.base.Preconditions.checkNotNull;
-
+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.namepath.NamePathMapper;
@@ -38,16 +40,19 @@ import org.apache.jackrabbit.oak.spi.com
import org.apache.jackrabbit.oak.spi.lifecycle.WorkspaceInitializer;
import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
-import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
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
* implementation uses the {@code UserManager} such as defined by the
@@ -99,8 +104,8 @@ class UserInitializer implements Workspa
} catch (CommitFailedException e) {
throw new RuntimeException(e);
}
- // TODO reconsider
- Root root = new RootImpl(store, commitHook, PostCommitHook.EMPTY, workspaceName, SystemSubject.INSTANCE, new OpenSecurityProvider(), indexProvider);
+
+ Root root = new SystemRootImpl(store, commitHook, workspaceName, securityProvider, indexProvider);
UserConfiguration userConfiguration = securityProvider.getConfiguration(UserConfiguration.class);
UserManager userManager = userConfiguration.getUserManager(root, NamePathMapper.DEFAULT);
@@ -144,4 +149,71 @@ class UserInitializer implements Workspa
}
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<Principal> getPrincipals() {
+ return SystemSubject.INSTANCE.getPrincipals();
+ }
+
+ @Override
+ public String[] getAttributeNames() {
+ return new String[]{};
+ }
+
+ @Override
+ public Object getAttribute(String attributeName) {
+ return null;
+ }
+ };
+ }
+ };
+ }
+ }
}