jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1503748 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Date Tue, 16 Jul 2013 15:07:00 GMT
Author: mduerig
Date: Tue Jul 16 15:07:00 2013
New Revision: 1503748

URL: http://svn.apache.org/r1503748
Log:
OAK-803 Backwards compatibility of long-lived sessions
make admin sessions refresh on every access

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java?rev=1503748&r1=1503747&r2=1503748&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
Tue Jul 16 15:07:00 2013
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.jcr;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
+import java.security.Principal;
 import java.util.concurrent.TimeUnit;
 
 import javax.annotation.Nonnull;
@@ -34,6 +35,7 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
+import org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal;
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -129,14 +131,27 @@ public class RepositoryImpl implements R
         try {
             ContentSession contentSession =
                     contentRepository.login(credentials, workspaceName);
+
+            // For better backwards compatibility admin sessions should always
+            // be on the latest revision: set refresh interval to 0. See OAK-803.
             SessionContext context = new SessionContext(
-                    this, whiteboard, new SessionDelegate(contentSession, AUTO_REFRESH_INTERVAL));
+                    this, whiteboard, new SessionDelegate(
+                            contentSession, isAdmin(contentSession) ? 0 : AUTO_REFRESH_INTERVAL));
             return context.getSession();
         } catch (LoginException e) {
             throw new javax.jcr.LoginException(e.getMessage(), e);
         }
     }
 
+    private static boolean isAdmin(ContentSession contentSession) {
+        for (Principal p : contentSession.getAuthInfo().getPrincipals()) {
+            if (p instanceof AdminPrincipal) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     /**
      * Calls {@link Repository#login(Credentials, String)} with
      * {@code null} arguments.

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java?rev=1503748&r1=1503747&r2=1503748&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Tue Jul 16 15:07:00 2013
@@ -1339,15 +1339,7 @@ public class RepositoryTest extends Abst
 
             session1.save();
 
-            // Make sure they are still not accessible through another session
-            assertFalse(session2.itemExists("/node1"));
-            assertFalse(session2.itemExists("/node1/node2"));
-            assertFalse(session2.itemExists("/node1/node3"));
-            assertFalse(session2.itemExists("/node1/node3/property1"));
-
-            session2.refresh(false);
-
-            // Make sure they are accessible through another session after refresh
+            // Make sure these items are still accessible through another session
             assertTrue(session2.itemExists("/node1"));
             assertTrue(session2.itemExists("/node1/node2"));
             assertTrue(session2.itemExists("/node1/node3"));
@@ -1450,8 +1442,8 @@ public class RepositoryTest extends Abst
             session1.save();
             session2.save();
             assertTrue(session1.getRootNode().hasNode("node1"));
-            assertFalse(session1.getRootNode().hasNode("node2")); // was not visible during
save
-            assertTrue(session2.getRootNode().hasNode("node1")); // save refreshes
+            assertTrue(session1.getRootNode().hasNode("node2"));
+            assertTrue(session2.getRootNode().hasNode("node1"));
             assertTrue(session2.getRootNode().hasNode("node2"));
         } finally {
             session1.logout();
@@ -1504,7 +1496,7 @@ public class RepositoryTest extends Abst
 
             session1.save();
             assertFalse(session1.getRootNode().hasNode("node"));
-            assertTrue(session2.getRootNode().hasNode("node"));
+            assertFalse(session2.getRootNode().hasNode("node"));
 
             try {
                 session2.save();



Mime
View raw message