From commits-return-9820-apmail-jackrabbit-commits-archive=jackrabbit.apache.org@jackrabbit.apache.org Thu Apr 08 13:00:37 2010 Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 42513 invoked from network); 8 Apr 2010 13:00:37 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Apr 2010 13:00:37 -0000 Received: (qmail 62275 invoked by uid 500); 8 Apr 2010 13:00:37 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 62176 invoked by uid 500); 8 Apr 2010 13:00:36 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 62169 invoked by uid 99); 8 Apr 2010 13:00:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Apr 2010 13:00:36 +0000 X-ASF-Spam-Status: No, hits=-1162.4 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Apr 2010 13:00:35 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D8CDA23889D5; Thu, 8 Apr 2010 13:00:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@jackrabbit.apache.org From: angela@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100408130014.D8CDA23889D5@eris.apache.org> 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 JCR-2595 + */ + 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()); + } + } }