jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r758654 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ main/java/org/apache/jackrabbit/core/security/user/ test/java/org/apache/jackrabbit/core/security/user/
Date Thu, 26 Mar 2009 14:12:10 GMT
Author: angela
Date: Thu Mar 26 14:11:57 2009
New Revision: 758654

URL: http://svn.apache.org/viewvc?rev=758654&view=rev
Log:
JCR-1588: Access Control

- dispose user manager upon session.logout

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/DefaultSecurityManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/DefaultSecurityManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/DefaultSecurityManager.java?rev=758654&r1=758653&r2=758654&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/DefaultSecurityManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/DefaultSecurityManager.java
Thu Mar 26 14:11:57 2009
@@ -322,8 +322,15 @@
             String workspaceName = securitySession.getWorkspace().getName();
             try {
                 SessionImpl sImpl = (SessionImpl) session;
-                SessionImpl s = (SessionImpl) sImpl.createSession(workspaceName);
-                return new UserManagerImpl(s, adminId);
+                UserManagerImpl uMgr;
+                if (workspaceName.equals(sImpl.getWorkspace().getName())) {
+                    uMgr = new UserManagerImpl(sImpl, adminId);
+                } else {
+                    SessionImpl s = (SessionImpl) sImpl.createSession(workspaceName);
+                    uMgr = new UserManagerImpl(s, adminId);
+                    sImpl.addListener(uMgr);
+                }
+                return uMgr;
             } catch (NoSuchWorkspaceException e) {
                 throw new AccessControlException("Cannot build UserManager for " + session.getUserID(),
e);
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java?rev=758654&r1=758653&r2=758654&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
Thu Mar 26 14:11:57 2009
@@ -25,6 +25,7 @@
 import org.apache.jackrabbit.core.NodeImpl;
 import org.apache.jackrabbit.core.ProtectedItemModifier;
 import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.SessionListener;
 import org.apache.jackrabbit.core.security.principal.ItemBasedPrincipal;
 import org.apache.jackrabbit.core.security.principal.PrincipalImpl;
 import org.apache.jackrabbit.spi.Name;
@@ -54,7 +55,7 @@
 /**
  * UserManagerImpl
  */
-public class UserManagerImpl extends ProtectedItemModifier implements UserManager, UserConstants
{
+public class UserManagerImpl extends ProtectedItemModifier implements UserManager, UserConstants,
SessionListener {
 
     private static final Logger log = LoggerFactory.getLogger(UserManagerImpl.class);
 
@@ -511,6 +512,26 @@
         return parent;
     }
 
+    //----------------------------------------------------< SessionListener >---
+    /**
+     * @see SessionListener#loggingOut(org.apache.jackrabbit.core.SessionImpl)
+     */
+    public void loggingOut(SessionImpl session) {
+        // nothing to do.
+    }
+
+    /**
+     * @see SessionListener#loggedOut(org.apache.jackrabbit.core.SessionImpl) 
+     */
+    public void loggedOut(SessionImpl session) {
+        // clear the map
+        idPathMap.clear();
+        // and logout the session unless it is the loggedout session itself.
+        if (session != this.session) {
+            this.session.logout();
+        }
+    }
+
     //--------------------------------------------------------------------------
     /**
      * Inner class

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java?rev=758654&r1=758653&r2=758654&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java
Thu Mar 26 14:11:57 2009
@@ -388,4 +388,52 @@
             // ok.
         }
     }
+
+    public void testCleanup() throws RepositoryException, NotExecutableException {
+        Session s = helper.getSuperuserSession();
+        try {
+            UserManager umgr = getUserManager(s);
+            s.logout();
+
+            // after logging out the session, the user manager must have been
+            // released as well and it's underlying session must not be available
+            // any more -> accessing users must fail.
+            try {
+                umgr.getAuthorizable("any userid");
+                fail("After having logged out the original session, the user manager must
not be live any more.");
+            } catch (RepositoryException e) {
+                // success
+            }
+        } finally {
+            if (s.isLive()) {
+                s.logout();
+            }
+        }
+    }
+
+    public void testCleanupForAllWorkspaces() throws RepositoryException, NotExecutableException
{
+        String[] workspaceNames = superuser.getWorkspace().getAccessibleWorkspaceNames();
+
+        for (int i = 0; i < workspaceNames.length; i++) {
+            Session s = helper.getSuperuserSession(workspaceNames[i]);
+            try {
+                UserManager umgr = getUserManager(s);
+                s.logout();
+
+                // after logging out the session, the user manager must have been
+                // released as well and it's underlying session must not be available
+                // any more -> accessing users must fail.
+                try {
+                    umgr.getAuthorizable("any userid");
+                    fail("After having logged out the original session, the user manager
must not be live any more.");
+                } catch (RepositoryException e) {
+                    // success
+                }
+            } finally {
+                if (s.isLive()) {
+                    s.logout();
+                }
+            }
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message