jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1519378 - in /jackrabbit/branches/2.4: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/ jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/u...
Date Mon, 02 Sep 2013 09:50:48 GMT
Author: mreutegg
Date: Mon Sep  2 09:50:47 2013
New Revision: 1519378

URL: http://svn.apache.org/r1519378
Log:
JCR-3658: MembershipCache not consistently synchronized
- Merge fix into 2.4 branch

Added:
    jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/MembershipCacheTest.java
      - copied unchanged from r1519376, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/MembershipCacheTest.java
    jackrabbit/branches/2.4/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/security/
      - copied from r1519376, jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/security/
    jackrabbit/branches/2.4/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/security/user/
      - copied from r1519376, jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/security/user/
    jackrabbit/branches/2.4/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/security/user/repository.xml
      - copied unchanged from r1519376, jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/security/user/repository.xml
Modified:
    jackrabbit/branches/2.4/   (props changed)
    jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/DefaultSecurityManager.java
    jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/MembershipCache.java

Propchange: jackrabbit/branches/2.4/
------------------------------------------------------------------------------
  Merged /jackrabbit/trunk:r1519376

Modified: jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/DefaultSecurityManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/DefaultSecurityManager.java?rev=1519378&r1=1519377&r2=1519378&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/DefaultSecurityManager.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/DefaultSecurityManager.java
Mon Sep  2 09:50:47 2013
@@ -49,6 +49,7 @@ import org.apache.jackrabbit.core.securi
 import org.apache.jackrabbit.core.security.DefaultAccessManager;
 import org.apache.jackrabbit.core.security.JackrabbitSecurityManager;
 import org.apache.jackrabbit.core.security.SecurityConstants;
+import org.apache.jackrabbit.core.security.SystemPrincipal;
 import org.apache.jackrabbit.core.security.authentication.AuthContext;
 import org.apache.jackrabbit.core.security.authentication.AuthContextProvider;
 import org.apache.jackrabbit.core.security.authorization.AccessControlProvider;
@@ -336,11 +337,15 @@ public class DefaultSecurityManager impl
     public String getUserID(Subject subject, String workspaceName) throws RepositoryException
{
         checkInitialized();
 
-        /* shortcut if the subject contains the AdminPrincipal in which case
-           the userID is already known. */
+        // shortcut if the subject contains the AdminPrincipal or
+        // SystemPrincipal in which cases the userID is already known.
         if (!subject.getPrincipals(AdminPrincipal.class).isEmpty()) {
             return adminId;
+        } else if (!subject.getPrincipals(SystemPrincipal.class).isEmpty()) {
+            // system session does not have a userId
+            return null;
         }
+
         /* if there is a configure principal class that should be used to
            determine the UserID -> try this one. */
         Class cl = getConfig().getUserIdClass();

Modified: jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/MembershipCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/MembershipCache.java?rev=1519378&r1=1519377&r2=1519378&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/MembershipCache.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/MembershipCache.java
Mon Sep  2 09:50:47 2013
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.core.secur
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Set;
 
 import javax.jcr.AccessDeniedException;
@@ -39,7 +38,7 @@ import org.apache.jackrabbit.core.NodeIm
 import org.apache.jackrabbit.core.PropertyImpl;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.SessionListener;
-import org.apache.jackrabbit.core.cache.GrowingLRUMap;
+import org.apache.jackrabbit.core.cache.ConcurrentCache;
 import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
 import org.apache.jackrabbit.core.observation.SynchronousEventListener;
 import org.apache.jackrabbit.spi.Name;
@@ -58,11 +57,6 @@ public class MembershipCache implements 
     private static final Logger log = LoggerFactory.getLogger(MembershipCache.class);
 
     /**
-     * The initial size of this cache (TODO: make configurable)
-     */
-    private static final int MAX_INITIAL_CACHE_SIZE = 1024;
-
-    /**
      * The maximum size of this cache (TODO: make configurable)
      */
     private static final int MAX_CACHE_SIZE = 5000;
@@ -71,7 +65,7 @@ public class MembershipCache implements 
     private final String groupsPath;
     private final boolean useMembersNode;
     private final String pMembers;
-    private final Map<String, Collection<String>> cache;
+    private final ConcurrentCache<String, Collection<String>> cache;
 
     @SuppressWarnings("unchecked")
     MembershipCache(SessionImpl systemSession, String groupsPath, boolean useMembersNode)
throws RepositoryException {
@@ -80,7 +74,8 @@ public class MembershipCache implements 
         this.useMembersNode = useMembersNode;
 
         pMembers = systemSession.getJCRName(UserManagerImpl.P_MEMBERS);
-        cache = new GrowingLRUMap(MAX_INITIAL_CACHE_SIZE, MAX_CACHE_SIZE);
+        cache = new ConcurrentCache<String, Collection<String>>("MembershipCache",
16);
+        cache.setMaxMemorySize(MAX_CACHE_SIZE);
 
         String[] ntNames = new String[] {
                 systemSession.getJCRName(UserConstants.NT_REP_GROUP),
@@ -143,9 +138,7 @@ public class MembershipCache implements 
         }
 
         if (clear) {
-            synchronized (cache) {
-                cache.clear();
-            }
+            cache.clear();
             log.debug("Membership cache cleared because of observation event.");
         }
     }
@@ -178,7 +171,7 @@ public class MembershipCache implements 
      * authorizable in question is declared member of.
      * @throws RepositoryException If an error occurs.
      */
-    synchronized Collection<String> getDeclaredMemberOf(String authorizableNodeIdentifier)
throws RepositoryException {
+    Collection<String> getDeclaredMemberOf(String authorizableNodeIdentifier) throws
RepositoryException {
         return declaredMemberOf(authorizableNodeIdentifier);
     }
 
@@ -189,7 +182,7 @@ public class MembershipCache implements 
      * authorizable in question is a direct or indirect member of.
      * @throws RepositoryException If an error occurs.
      */
-    synchronized Collection<String> getMemberOf(String authorizableNodeIdentifier)
throws RepositoryException {
+    Collection<String> getMemberOf(String authorizableNodeIdentifier) throws RepositoryException
{
         Set<String> groupNodeIds = new HashSet<String>();
         memberOf(authorizableNodeIdentifier, groupNodeIds);
         return Collections.unmodifiableCollection(groupNodeIds);
@@ -199,8 +192,15 @@ public class MembershipCache implements 
      * Returns the size of the membership cache
      * @return the size
      */
-    synchronized int getSize() {
-        return cache.size();
+    int getSize() {
+        return (int) cache.getElementCount();
+    }
+
+    /**
+     * For testing purposes only.
+     */
+    void clear() {
+        cache.clear();
     }
 
     /**
@@ -282,7 +282,7 @@ public class MembershipCache implements 
             Session session = getSession();
             try {
                 groupNodeIds = collectDeclaredMembership(authorizableNodeIdentifier, session);
-                cache.put(authorizableNodeIdentifier, Collections.unmodifiableCollection(groupNodeIds));
+                cache.put(authorizableNodeIdentifier, Collections.unmodifiableCollection(groupNodeIds),
1);
             }
             finally {
                 // release session if it isn't the original system session
@@ -299,7 +299,7 @@ public class MembershipCache implements 
                     groupNodeIds.size(),
                     authorizableNodeIdentifier,
                     (t1-t0) / 1000,
-                    cache.size()
+                    cache.getElementCount()
             });
         }
         return groupNodeIds;



Mime
View raw message