jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r931919 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/SessionImpl.java test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java
Date Thu, 08 Apr 2010 13:00:14 GMT
Author: angela
Date: Thu Apr  8 13:00:14 2010
New Revision: 931919

URL: http://svn.apache.org/viewvc?rev=931919&view=rev
Log:
JCR-2595: SessionImpl.createSession uses same Subject/LoginContext

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=931919&r1=931918&r2=931919&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Thu Apr  8 13:00:14 2010
@@ -428,11 +428,9 @@ public class SessionImpl extends Abstrac
         if (workspaceName == null) {
             workspaceName = rep.getConfig().getDefaultWorkspaceName();
         }
-        if (loginContext != null) {
-            return rep.createSession(loginContext, workspaceName);
-        } else {
-            return rep.createSession(getSubject(), workspaceName);
-        }
+        Subject old = getSubject();
+        Subject newSubject = new Subject(old.isReadOnly(), old.getPrincipals(), old.getPublicCredentials(),
old.getPrivateCredentials());
+        return rep.createSession(newSubject, workspaceName);
     }
 
     /**
@@ -804,6 +802,7 @@ public class SessionImpl extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     public Session impersonate(Credentials otherCredentials)
             throws LoginException, RepositoryException {
         // check sanity of this session
@@ -864,6 +863,7 @@ public class SessionImpl extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     public Item getItem(String absPath) throws PathNotFoundException, RepositoryException
{
         // check sanity of this session
         sanityCheck();
@@ -886,6 +886,7 @@ public class SessionImpl extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     public boolean itemExists(String absPath) throws RepositoryException {
         // check sanity of this session
         sanityCheck();
@@ -1206,6 +1207,7 @@ public class SessionImpl extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     public synchronized void logout() {
         if (!alive) {
             // ignore
@@ -1294,6 +1296,7 @@ public class SessionImpl extends Abstrac
     /**
      * {@inheritDoc}
      */
+    @Override
     public void setNamespacePrefix(String prefix, String uri)
             throws NamespaceException, RepositoryException {
         super.setNamespacePrefix(prefix, uri);
@@ -1386,6 +1389,7 @@ public class SessionImpl extends Abstrac
      * @see javax.jcr.Session#getNode(String)
      * @since JCR 2.0
      */
+    @Override
     public Node getNode(String absPath)
             throws PathNotFoundException, RepositoryException {
         // check sanity of this session
@@ -1410,6 +1414,7 @@ public class SessionImpl extends Abstrac
      * @see javax.jcr.Session#getProperty(String)
      * @since JCR 2.0
      */
+    @Override
     public Property getProperty(String absPath)
             throws PathNotFoundException, RepositoryException {
         // check sanity of this session
@@ -1434,6 +1439,7 @@ public class SessionImpl extends Abstrac
      * @see javax.jcr.Session#nodeExists(String)
      * @since JCR 2.0
      */
+    @Override
     public boolean nodeExists(String absPath) throws RepositoryException {
         // check sanity of this session
         sanityCheck();
@@ -1455,6 +1461,7 @@ public class SessionImpl extends Abstrac
      * @see javax.jcr.Session#propertyExists(String)
      * @since JCR 2.0
      */
+    @Override
     public boolean propertyExists(String absPath) throws RepositoryException {
         // check sanity of this session
         sanityCheck();
@@ -1476,6 +1483,7 @@ public class SessionImpl extends Abstrac
      * @see javax.jcr.Session#removeItem(String)
      * @since JCR 2.0
      */
+    @Override
     public void removeItem(String absPath) throws VersionException,
             LockException, ConstraintViolationException, RepositoryException {
         // check sanity of this session
@@ -1662,6 +1670,7 @@ public class SessionImpl extends Abstrac
      * the session is closed automatically; however a warning is written to the log file,
      * together with the stack trace of where the session was opened.
      */
+    @Override
     public void finalize() {
         if (alive) {
             log.warn("Unclosed session detected. The session was opened here: ", openStackTrace);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java?rev=931919&r1=931918&r2=931919&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java
Thu Apr  8 13:00:14 2010
@@ -22,8 +22,12 @@ import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
+import javax.security.auth.Subject;
 
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
 
 /**
  * Integration tests for the Session implementation in Jackrabbit core.
@@ -70,4 +74,60 @@ public class SessionImplTest extends Abs
         }
     }
 
+    /**
+     * JCR-2595: SessionImpl.createSession uses same Subject/LoginContext
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-2595">JCR-2595</a>
+     */
+    public void testCreateSession() throws RepositoryException, NotExecutableException {
+        if (!(superuser instanceof SessionImpl)) {
+            throw new NotExecutableException();
+        }
+
+        String currentWsp = superuser.getWorkspace().getName();
+        String otherWsp = null;
+        for (String wsp : superuser.getWorkspace().getAccessibleWorkspaceNames()) {
+            if (!wsp.equals(currentWsp)) {
+                otherWsp = wsp;
+                break;
+            }
+        }
+
+        SessionImpl sImpl = (SessionImpl) superuser;
+        Subject subject = sImpl.getSubject();
+
+        Session s1 = sImpl.createSession(currentWsp);
+        try {
+            assertFalse(s1 == sImpl);
+            assertFalse(subject == ((SessionImpl) s1).getSubject());
+            assertEquals(subject, ((SessionImpl) s1).getSubject());
+            assertEquals(currentWsp, s1.getWorkspace().getName());
+        } finally {
+            s1.logout();
+            assertFalse(subject.getPrincipals().isEmpty());
+        }
+
+
+        Session s2 = sImpl.createSession(otherWsp);
+        try {
+            assertFalse(s2 == sImpl);
+            assertFalse(subject == ((SessionImpl) s2).getSubject());
+            assertEquals(subject, ((SessionImpl) s2).getSubject());
+            assertEquals(otherWsp, s2.getWorkspace().getName());
+        } finally {
+            s2.logout();
+            assertFalse(subject.getPrincipals().isEmpty());
+        }
+
+        Session s3 = sImpl.createSession(null);
+        try {
+            assertFalse(s3 == sImpl);
+            assertFalse(subject == ((SessionImpl) s3).getSubject());
+            assertEquals(subject, ((SessionImpl) s3).getSubject());
+            assertEquals(((RepositoryImpl) sImpl.getRepository()).getConfig().getDefaultWorkspaceName(),
s3.getWorkspace().getName());
+        } finally {
+            s3.logout();
+            assertFalse(subject.getPrincipals().isEmpty());
+        }
+    }
 }



Mime
View raw message