jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1581325 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: delegate/ observation/ repository/ security/ session/
Date Tue, 25 Mar 2014 13:53:35 GMT
Author: angela
Date: Tue Mar 25 13:53:34 2014
New Revision: 1581325

URL: http://svn.apache.org/r1581325
Log:
OAK-1592 : Performance of Session#hasPermission

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java?rev=1581325&r1=1581324&r2=1581325&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
Tue Mar 25 13:53:34 2014
@@ -16,23 +16,12 @@
  */
 package org.apache.jackrabbit.oak.jcr.delegate;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.concurrent.TimeUnit.NANOSECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_COUNTER;
-import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_DURATION;
-import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_COUNTER;
-import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_DURATION;
-import static org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot;
-
 import java.io.IOException;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.ItemExistsException;
@@ -41,7 +30,6 @@ import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.ConstraintViolationException;
 
 import com.google.common.collect.ImmutableMap;
-
 import org.apache.jackrabbit.oak.api.AuthInfo;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentSession;
@@ -54,6 +42,9 @@ import org.apache.jackrabbit.oak.jcr.ses
 import org.apache.jackrabbit.oak.jcr.session.SessionStats;
 import org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
+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.stats.Clock;
 import org.apache.jackrabbit.oak.stats.StatisticManager;
 import org.slf4j.Logger;
@@ -61,6 +52,16 @@ import org.slf4j.LoggerFactory;
 import org.slf4j.Marker;
 import org.slf4j.MarkerFactory;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_COUNTER;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_READ_DURATION;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_COUNTER;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_WRITE_DURATION;
+import static org.apache.jackrabbit.oak.commons.PathUtils.denotesRoot;
+
 /**
  * TODO document
  */
@@ -69,6 +70,7 @@ public class SessionDelegate {
     static final Logger operationLogger = LoggerFactory.getLogger("org.apache.jackrabbit.oak.jcr.operations");
 
     private final ContentSession contentSession;
+    private final SecurityProvider securityProvider;
     private final RefreshStrategy refreshStrategy;
     private boolean refreshAtNextAccess = false;
 
@@ -117,6 +119,8 @@ public class SessionDelegate {
 
     private String userData = null;
 
+    private PermissionProvider permissionProvider;
+
     /**
      * The lock used to guarantee synchronized execution of repository
      * operations. An explicit lock is used instead of normal Java
@@ -134,16 +138,19 @@ public class SessionDelegate {
      * dispatcher in order.
      *
      * @param contentSession  the content session
+     * @param securityProvider the security provider
      * @param refreshStrategy  the refresh strategy used for auto refreshing this session
      * @param statisticManager the statistics manager for tracking session operations
      */
     public SessionDelegate(
             @Nonnull ContentSession contentSession,
+            @Nonnull SecurityProvider securityProvider,
             @Nonnull RefreshStrategy refreshStrategy,
             @Nonnull ThreadLocal<Long> threadSaveCount,
             @Nonnull StatisticManager statisticManager,
             @Nonnull Clock clock) {
         this.contentSession = checkNotNull(contentSession);
+        this.securityProvider = checkNotNull(securityProvider);
         this.refreshStrategy = checkNotNull(refreshStrategy);
         this.threadSaveCount = checkNotNull(threadSaveCount);
         this.sessionSaveCount = getThreadSaveCount();
@@ -396,6 +403,9 @@ public class SessionDelegate {
             info.put(EventFactory.USER_DATA, userData);
         }
         root.commit(info.build());
+        if (permissionProvider != null) {
+            permissionProvider.refresh();
+        }
     }
 
     /**
@@ -554,6 +564,9 @@ public class SessionDelegate {
         } else {
             root.refresh();
         }
+        if (permissionProvider != null) {
+            permissionProvider.refresh();
+        }
     }
 
     //----------------------------------------------------------< Workspace >---
@@ -615,6 +628,16 @@ public class SessionDelegate {
         return root.getQueryEngine();
     }
 
+    @Nonnull
+    public PermissionProvider getPermissionProvider() {
+        if (permissionProvider == null) {
+            permissionProvider = checkNotNull(securityProvider)
+                    .getConfiguration(AuthorizationConfiguration.class)
+                    .getPermissionProvider(root, getWorkspaceName(), getAuthInfo().getPrincipals());
+        }
+        return permissionProvider;
+    }
+
     /**
      * The current {@code Root} instance this session delegate instance operates on.
      * To ensure the returned root reflects the correct repository revision access

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java?rev=1581325&r1=1581324&r2=1581325&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
Tue Mar 25 13:53:34 2014
@@ -18,17 +18,11 @@
  */
 package org.apache.jackrabbit.oak.jcr.observation;
 
-import static com.google.common.collect.Lists.newArrayList;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static org.apache.jackrabbit.oak.plugins.observation.filter.GlobbingPathFilter.STAR;
-import static org.apache.jackrabbit.oak.plugins.observation.filter.GlobbingPathFilter.STAR_STAR;
-
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import javax.jcr.RepositoryException;
@@ -54,6 +48,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider;
 import org.apache.jackrabbit.oak.plugins.observation.filter.Selectors;
 import org.apache.jackrabbit.oak.spi.commit.Observable;
+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.whiteboard.Whiteboard;
 import org.apache.jackrabbit.oak.stats.StatisticManager;
@@ -62,6 +57,11 @@ import org.slf4j.LoggerFactory;
 import org.slf4j.Marker;
 import org.slf4j.MarkerFactory;
 
+import static com.google.common.collect.Lists.newArrayList;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.jackrabbit.oak.plugins.observation.filter.GlobbingPathFilter.STAR;
+import static org.apache.jackrabbit.oak.plugins.observation.filter.GlobbingPathFilter.STAR_STAR;
+
 public class ObservationManagerImpl implements JackrabbitObservationManager {
     private static final Logger LOG = LoggerFactory.getLogger(ObservationManagerImpl.class);
     private static final int STOP_TIME_OUT = 1000;
@@ -77,7 +77,7 @@ public class ObservationManagerImpl impl
 
     private final SessionDelegate sessionDelegate;
     private final ReadOnlyNodeTypeManager ntMgr;
-    private final PermissionProvider permissionProvider;
+    private final AuthorizationConfiguration authorizationConfig;
     private final NamePathMapper namePathMapper;
     private final Whiteboard whiteboard;
     private final StatisticManager statisticManager;
@@ -96,12 +96,11 @@ public class ObservationManagerImpl impl
      */
     public ObservationManagerImpl(
             SessionContext sessionContext, ReadOnlyNodeTypeManager nodeTypeManager,
-            PermissionProvider permissionProvider, Whiteboard whiteboard,
-            int queueLength, CommitRateLimiter commitRateLimiter) {
+            Whiteboard whiteboard, int queueLength, CommitRateLimiter commitRateLimiter)
{
 
         this.sessionDelegate = sessionContext.getSessionDelegate();
+        this.authorizationConfig = sessionContext.getSecurityProvider().getConfiguration(AuthorizationConfiguration.class);
         this.ntMgr = nodeTypeManager;
-        this.permissionProvider = permissionProvider;
         this.namePathMapper = sessionContext;
         this.whiteboard = whiteboard;
         this.statisticManager = sessionContext.getStatisticManager();
@@ -138,7 +137,7 @@ public class ObservationManagerImpl impl
             LOG.debug(OBSERVATION,
                     "Registering event listener {} with filter {}", listener, filterProviders);
             processor = new ChangeProcessor(sessionDelegate.getContentSession(), namePathMapper,
-                    permissionProvider, tracker, filterProviders, statisticManager, queueLength,
+                    createPermissionProvider(), tracker, filterProviders, statisticManager,
queueLength,
                     commitRateLimiter);
             processors.put(listener, processor);
             processor.start(whiteboard);
@@ -298,6 +297,15 @@ public class ObservationManagerImpl impl
     }
 
     //------------------------------------------------------------< private >---
+    /**
+     * Create a new permission provider instance for the current revision of the
+     * {@code Root} associated with the {@code sessionDelegate}.
+     *
+     * @return a new permission provider.
+     */
+    private PermissionProvider createPermissionProvider() {
+        return authorizationConfig.getPermissionProvider(sessionDelegate.getRoot(), sessionDelegate.getWorkspaceName(),
sessionDelegate.getAuthInfo().getPrincipals());
+    }
 
     /**
      * Validates the given node type names.

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java?rev=1581325&r1=1581324&r2=1581325&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
Tue Mar 25 13:53:34 2014
@@ -16,14 +16,11 @@
  */
 package org.apache.jackrabbit.oak.jcr.repository;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 import java.util.Collections;
 import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -40,28 +37,29 @@ import com.google.common.util.concurrent
 import com.google.common.util.concurrent.ListenableScheduledFuture;
 import com.google.common.util.concurrent.ListeningScheduledExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
-
 import org.apache.jackrabbit.api.JackrabbitRepository;
 import org.apache.jackrabbit.api.security.authentication.token.TokenCredentials;
 import org.apache.jackrabbit.commons.SimpleValueFactory;
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.jmx.SessionMBean;
-import org.apache.jackrabbit.oak.plugins.observation.CommitRateLimiter;
-import org.apache.jackrabbit.oak.stats.Clock;
-import org.apache.jackrabbit.oak.stats.StatisticManager;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.jcr.session.RefreshStrategy;
 import org.apache.jackrabbit.oak.jcr.session.SessionContext;
 import org.apache.jackrabbit.oak.jcr.session.SessionStats;
+import org.apache.jackrabbit.oak.plugins.observation.CommitRateLimiter;
 import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.apache.jackrabbit.oak.spi.whiteboard.Registration;
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
 import org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils;
+import org.apache.jackrabbit.oak.stats.Clock;
+import org.apache.jackrabbit.oak.stats.StatisticManager;
 import org.apache.jackrabbit.oak.util.GenericDescriptors;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 /**
  * TODO document
  */
@@ -257,7 +255,7 @@ public class RepositoryImpl implements J
             final RefreshStrategy refreshStrategy,
             final ContentSession contentSession) {
         return new SessionDelegate(
-                contentSession, refreshStrategy,
+                contentSession, securityProvider, refreshStrategy,
                 threadSaveCount, statisticManager, clock) {
             // Defer session MBean registration to avoid cluttering the
             // JMX name space with short lived sessions

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java?rev=1581325&r1=1581324&r2=1581325&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java
Tue Mar 25 13:53:34 2014
@@ -44,7 +44,6 @@ public class AccessManager {
         return delegate.safePerform(new SessionOperation<Boolean>("hasPermissions")
{
             @Override
             public Boolean perform() {
-                permissionProvider.refresh();
                 return permissionProvider.isGranted(oakPath, actions);
             }
         });
@@ -54,7 +53,6 @@ public class AccessManager {
         return delegate.safePerform(new SessionOperation<Boolean>("hasPermissions")
{
             @Override
             public Boolean perform() {
-                permissionProvider.refresh();
                 return permissionProvider.isGranted(tree, property, permissions);
             }
         });

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java?rev=1581325&r1=1581324&r2=1581325&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
Tue Mar 25 13:53:34 2014
@@ -16,17 +16,12 @@
  */
 package org.apache.jackrabbit.oak.jcr.session;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Sets.newHashSet;
-import static com.google.common.collect.Sets.newTreeSet;
-
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.PathNotFoundException;
@@ -62,7 +57,6 @@ import org.apache.jackrabbit.oak.plugins
 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;
 import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration;
 import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
@@ -72,6 +66,10 @@ import org.apache.jackrabbit.oak.stats.S
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Sets.newHashSet;
+import static com.google.common.collect.Sets.newTreeSet;
+
 /**
  * Instances of this class are passed to all JCR implementation classes
  * (e.g. {@code SessionImpl}, {@code NodeImpl}, etc.) and provide access to
@@ -98,7 +96,6 @@ public class SessionContext implements N
     private SessionImpl session = null;
     private WorkspaceImpl workspace = null;
 
-    private PermissionProvider permissionProvider;
     private AccessControlManager accessControlManager;
     private AccessManager accessManager;
     private PrincipalManager principalManager;
@@ -270,7 +267,7 @@ public class SessionContext implements N
             observationManager = new ObservationManagerImpl(
                 this,
                 ReadOnlyNodeTypeManager.getInstance(delegate.getRoot(), namePathMapper),
-                getPermissionProvider(), whiteboard, observationQueueLength, commitRateLimiter);
+                whiteboard, observationQueueLength, commitRateLimiter);
         }
         return observationManager;
     }
@@ -365,7 +362,7 @@ public class SessionContext implements N
     @Nonnull
     public AccessManager getAccessManager() throws RepositoryException {
         if (accessManager == null) {
-            accessManager = new AccessManager(delegate, getPermissionProvider());
+            accessManager = new AccessManager(delegate, delegate.getPermissionProvider());
         }
         return accessManager;
     }
@@ -422,16 +419,4 @@ public class SessionContext implements N
         return securityProvider.getConfiguration(clss);
     }
 
-    private PermissionProvider getPermissionProvider() {
-        // FIXME: review whether 'auto-refresh' should rather be made on a wrapping
-        //        permission provider instead of doing this in the access manager
-        //        since this permission provider is also passed to the observation manager.
-        if (permissionProvider == null) {
-            permissionProvider = checkNotNull(securityProvider)
-                    .getConfiguration(AuthorizationConfiguration.class)
-                    .getPermissionProvider(delegate.getRoot(), delegate.getWorkspaceName(),
delegate.getAuthInfo().getPrincipals());
-        }
-        return permissionProvider;
-    }
-
 }



Mime
View raw message