Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 10064 invoked from network); 16 Feb 2009 16:11:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Feb 2009 16:11:03 -0000 Received: (qmail 29066 invoked by uid 500); 16 Feb 2009 16:11:02 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 29038 invoked by uid 500); 16 Feb 2009 16:11:02 -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 29029 invoked by uid 99); 16 Feb 2009 16:11:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Feb 2009 08:11:02 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED 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; Mon, 16 Feb 2009 16:11:01 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3455A23888A3; Mon, 16 Feb 2009 16:10:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r744954 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/RepositoryImpl.java main/java/org/apache/jackrabbit/core/SessionImpl.java test/java/org/apache/jackrabbit/core/integration/SessionImplTest.java Date: Mon, 16 Feb 2009 16:10:16 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090216161041.3455A23888A3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Mon Feb 16 16:09:59 2009 New Revision: 744954 URL: http://svn.apache.org/viewvc?rev=744954&view=rev Log: JCR-1932: Session.getAttributes( ) call always returns an empty array Added a protected SessionImpl.setAttribute() method to set the attributes of a session. Use the method in RepositoryImpl.login() when a SimpleCredentials instance has been passed. Added a test case for this. Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java 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/RepositoryImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=744954&r1=744953&r2=744954&view=diff ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java Mon Feb 16 16:09:59 2009 @@ -83,6 +83,7 @@ import javax.jcr.NoSuchWorkspaceException; import javax.jcr.RepositoryException; import javax.jcr.Session; +import javax.jcr.SimpleCredentials; import javax.jcr.observation.Event; import javax.jcr.observation.EventIterator; import javax.jcr.observation.EventListener; @@ -1409,9 +1410,17 @@ // not preauthenticated -> try login with credentials AuthContext authCtx = getSecurityManager().getAuthContext(credentials, new Subject()); authCtx.login(); - // create session - return createSession(authCtx, workspaceName); + // create session, and add SimpleCredentials attributes (JCR-1932) + SessionImpl session = createSession(authCtx, workspaceName); + if (credentials instanceof SimpleCredentials) { + SimpleCredentials sc = (SimpleCredentials) credentials; + String[] names = sc.getAttributeNames(); + for (int i = 0; i < names.length; i++) { + session.setAttribute(names[i], sc.getAttribute(names[i])); + } + } + return session; } catch (SecurityException se) { throw new LoginException("Unable to access authentication information", se); } catch (javax.security.auth.login.LoginException le) { 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=744954&r1=744953&r2=744954&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 Mon Feb 16 16:09:59 2009 @@ -493,6 +493,23 @@ } /** + * Sets the named attribute. If the value is null, then + * the named attribute is removed. + * + * @see JCR-1932 + * @param name attribute name + * @param value attribute value + * @since Apache Jackrabbit 1.6 + */ + protected void setAttribute(String name, Object value) { + if (value != null) { + attributes.put(name, value); + } else { + attributes.remove(name); + } + } + + /** * Retrieves the referenceable node with the given UUID. * * @param uuid uuid of the node to be retrieved 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=744954&r1=744953&r2=744954&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 Mon Feb 16 16:09:59 2009 @@ -21,6 +21,7 @@ import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; +import javax.jcr.SimpleCredentials; import org.apache.jackrabbit.test.AbstractJCRTest; @@ -48,4 +49,25 @@ session.logout(); } } + + /** + * JCR-1932: Session.getAttributes( ) call always returns an empty array + * + * @see JCR-1932 + */ + public void testSessionAttributes() throws RepositoryException { + SimpleCredentials credentials = + new SimpleCredentials("admin", "admin".toCharArray()); + credentials.setAttribute("test", "attribute"); + Session session = helper.getRepository().login(credentials); + try { + String[] names = session.getAttributeNames(); + assertEquals(1, names.length); + assertEquals("test", names[0]); + assertEquals("attribute", session.getAttribute("test")); + } finally { + session.logout(); + } + } + }