jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1511301 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/ oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/ oak-core/src/main/java/org/apache/jackrabbi...
Date Wed, 07 Aug 2013 13:31:42 GMT
Author: mduerig
Date: Wed Aug  7 13:31:42 2013
New Revision: 1511301

URL: http://svn.apache.org/r1511301
Log:
OAK-945: UserImporter should not cast UserManager to UserManagerImpl

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationConfigurationImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlImporter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/ProtectedItemImporter.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationConfigurationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationConfigurationImpl.java?rev=1511301&r1=1511300&r2=1511301&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationConfigurationImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationConfigurationImpl.java
Wed Aug  7 13:31:42 2013
@@ -93,7 +93,7 @@ public class AuthorizationConfigurationI
     @Nonnull
     @Override
     public List<ProtectedItemImporter> getProtectedItemImporters() {
-        return Collections.<ProtectedItemImporter>singletonList(new AccessControlImporter(getSecurityProvider()));
+        return Collections.<ProtectedItemImporter>singletonList(new AccessControlImporter());
     }
 
     //-----------------------------------------< AccessControlConfiguration >---

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlImporter.java?rev=1511301&r1=1511300&r2=1511301&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlImporter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlImporter.java
Wed Aug  7 13:31:42 2013
@@ -16,11 +16,14 @@
  */
 package org.apache.jackrabbit.oak.security.authorization.accesscontrol;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+
 import javax.annotation.CheckForNull;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -52,8 +55,6 @@ import org.apache.jackrabbit.oak.spi.xml
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 /**
  * {@link ProtectedNodeImporter} implementation that handles access control lists,
  * entries and restrictions.
@@ -66,8 +67,6 @@ public class AccessControlImporter imple
     private static final int CHILD_STATUS_ACE = 1;
     private static final int CHILD_STATUS_RESTRICTION = 2;
 
-    private final SecurityProvider securityProvider;
-
     private AccessControlManager acMgr;
     private PrincipalManager principalManager;
     private ReadOnlyNodeTypeManager ntMgr;
@@ -78,16 +77,12 @@ public class AccessControlImporter imple
     private JackrabbitAccessControlList acl;
     private MutableEntry entry;
 
-    public AccessControlImporter(SecurityProvider securityProvider) {
-        this.securityProvider = securityProvider;
-    }
-
     //----------------------------------------------< ProtectedItemImporter >---
 
     @Override
     public boolean init(Session session, Root root, NamePathMapper namePathMapper,
-                        boolean isWorkspaceImport, int uuidBehavior,
-                        ReferenceChangeTracker referenceTracker) {
+            boolean isWorkspaceImport, int uuidBehavior,
+            ReferenceChangeTracker referenceTracker, SecurityProvider securityProvider) {
         if (initialized) {
             throw new IllegalStateException("Already initialized");
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java?rev=1511301&r1=1511300&r2=1511301&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
Wed Aug  7 13:31:42 2013
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.oak.security.user;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -25,6 +28,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.jcr.ImportUUIDBehavior;
@@ -41,7 +45,6 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.api.security.user.Group;
 import org.apache.jackrabbit.api.security.user.Impersonation;
 import org.apache.jackrabbit.api.security.user.User;
-import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
@@ -49,6 +52,7 @@ import org.apache.jackrabbit.oak.api.Typ
 import org.apache.jackrabbit.oak.core.IdentifierManager;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
+import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.xml.ImportBehavior;
@@ -62,9 +66,6 @@ import org.apache.jackrabbit.oak.util.Tr
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.api.Type.STRINGS;
-
 /**
  * {@code UserImporter} implements both {@code ode>ProtectedPropertyImporter}
  * and {@code ProtectedNodeImporter} and provides import facilities for protected
@@ -157,8 +158,8 @@ class UserImporter implements ProtectedP
     //----------------------------------------------< ProtectedItemImporter >---
     @Override
     public boolean init(Session session, Root root, NamePathMapper namePathMapper,
-                        boolean isWorkspaceImport, int uuidBehavior,
-                        ReferenceChangeTracker referenceTracker) {
+            boolean isWorkspaceImport, int uuidBehavior,
+            ReferenceChangeTracker referenceTracker, SecurityProvider securityProvider) {
 
         if (!(session instanceof JackrabbitSession)) {
             log.debug("Importing protected user content requires a JackrabbitSession");
@@ -178,43 +179,12 @@ class UserImporter implements ProtectedP
             return false;
         }
 
-        if (!initUserManager(isWorkspaceImport)) {
-            return false;
-        }
+        userManager = new UserManagerImpl(root, namePathMapper, securityProvider);
 
         initialized = true;
         return initialized;
     }
 
-    private boolean initUserManager(boolean isWorkspaceImport) {
-        try {
-            UserManager uMgr = session.getUserManager();
-            if (uMgr instanceof UserManagerImpl) {
-                UserManagerImpl impl = (UserManagerImpl) uMgr;
-                if (isWorkspaceImport) {
-                    // use a separate user manager that is not associated with
-                    // transient session modifications.
-                    userManager = new UserManagerImpl(root, namePathMapper, impl.getSecurityProvider());
-                    return true;
-                } else {
-                    if (impl.isAutoSave()) {
-                        log.warn("Session import cannot handle user content: UserManager
is in autosave mode.");
-                    } else {
-                        userManager = impl;
-                        return true;
-                    }
-                }
-            } else {
-                log.debug("Failed to initialize UserImporter: Instanceof UserManagerImpl
expected.");
-            }
-        } catch (RepositoryException e) {
-            // failed to access user manager or to set the autosave behavior
-            // -> return false (not initialized) as importer can't operate.
-            log.error("Failed to initialize UserImporter: ", e);
-        }
-        return false;
-    }
-
     // -----------------------------------------< ProtectedPropertyImporter >---
     @Override
     public boolean handlePropInfo(Tree parent, PropInfo propInfo, PropertyDefinition def)
throws RepositoryException {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/ProtectedItemImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/ProtectedItemImporter.java?rev=1511301&r1=1511300&r2=1511301&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/ProtectedItemImporter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/ProtectedItemImporter.java
Wed Aug  7 13:31:42 2013
@@ -22,6 +22,7 @@ import javax.jcr.Session;
 
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
+import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 
 /**
  * Base interface for {@link ProtectedNodeImporter} and {@link ProtectedPropertyImporter}.
@@ -48,13 +49,14 @@ public interface ProtectedItemImporter {
      * version operations are required to never leave transient changes behind.
      * @param uuidBehavior The uuid behavior specified with the import call.
      * @param referenceTracker The uuid/reference helper.
+     * @param securityProvider The security provider.
      * @return {@code true} if this importer was successfully initialized and
      * is able to handle an import with the given setup; {@code false} otherwise.
      */
     boolean init(@Nonnull Session session, @Nonnull Root root,
-                 @Nonnull NamePathMapper namePathMapper,
-                 boolean isWorkspaceImport, int uuidBehavior,
-                 @Nonnull ReferenceChangeTracker referenceTracker);
+            @Nonnull NamePathMapper namePathMapper,
+            boolean isWorkspaceImport, int uuidBehavior,
+            @Nonnull ReferenceChangeTracker referenceTracker, SecurityProvider securityProvider);
 
     /**
      * Post processing protected reference properties underneath a protected

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java?rev=1511301&r1=1511300&r2=1511301&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
Wed Aug  7 13:31:42 2013
@@ -16,9 +16,12 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.PathNotFoundException;
@@ -57,6 +60,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.observation.Observable;
 import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
 import org.apache.jackrabbit.oak.spi.security.SecurityConfiguration;
+import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration;
 import org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider;
 import org.apache.jackrabbit.oak.spi.security.principal.PrincipalConfiguration;
@@ -65,8 +69,6 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
 import org.apache.jackrabbit.oak.spi.xml.ProtectedItemImporter;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 /**
  * Instances of this class are passed to all JCR implementation classes
  * (e.g. {@code SessionImpl}, {@code NodeImpl}, etc.) and provide access to
@@ -330,6 +332,11 @@ public class SessionContext implements N
         return new AccessManager(getPermissionProvider());
     }
 
+    @Nonnull
+    public SecurityProvider getSecurityProvider() {
+        return repository.getSecurityProvider();
+    }
+
     //-----------------------------------------------------------< internal >---
 
     void dispose() {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java?rev=1511301&r1=1511300&r2=1511301&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
Wed Aug  7 13:31:42 2013
@@ -16,11 +16,14 @@
  */
 package org.apache.jackrabbit.oak.jcr.xml;
 
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
+
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Stack;
 import java.util.UUID;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.ImportUUIDBehavior;
@@ -61,8 +64,6 @@ import org.apache.jackrabbit.oak.util.Tr
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
-
 public class ImporterImpl implements Importer {
     private static final Logger log = LoggerFactory.getLogger(ImporterImpl.class);
 
@@ -150,7 +151,8 @@ public class ImporterImpl implements Imp
 
         pItemImporters.clear();
         for (ProtectedItemImporter importer : sessionContext.getProtectedItemImporters())
{
-            if (importer.init(sessionContext.getSession(), root, sessionContext, isWorkspaceImport,
uuidBehavior, refTracker)) {
+            // FIXME this passes the session scoped name path mapper also for workspace imports
+            if (importer.init(sessionContext.getSession(), root, sessionContext, isWorkspaceImport,
uuidBehavior, refTracker, sessionContext.getSecurityProvider())) {
                 pItemImporters.add(importer);
             }
         }



Mime
View raw message