Return-Path: Delivered-To: apmail-incubator-shiro-commits-archive@www.apache.org Received: (qmail 22836 invoked from network); 6 Jan 2010 22:21:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 6 Jan 2010 22:21:03 -0000 Received: (qmail 80411 invoked by uid 500); 6 Jan 2010 22:21:03 -0000 Delivered-To: apmail-incubator-shiro-commits-archive@incubator.apache.org Received: (qmail 80390 invoked by uid 500); 6 Jan 2010 22:21:03 -0000 Mailing-List: contact shiro-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: shiro-dev@incubator.apache.org Delivered-To: mailing list shiro-commits@incubator.apache.org Received: (qmail 80380 invoked by uid 99); 6 Jan 2010 22:21:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jan 2010 22:21:03 +0000 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; Wed, 06 Jan 2010 22:21:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5BE3A23888CF; Wed, 6 Jan 2010 22:20:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r896696 - in /incubator/shiro/trunk/core/src/main/java/org/apache/shiro: subject/Subject.java subject/support/SubjectThreadState.java util/ThreadContext.java Date: Wed, 06 Jan 2010 22:20:39 -0000 To: shiro-commits@incubator.apache.org From: lhazlewood@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100106222039.5BE3A23888CF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: lhazlewood Date: Wed Jan 6 22:20:38 2010 New Revision: 896696 URL: http://svn.apache.org/viewvc?rev=896696&view=rev Log: Removed unnecessary thread-binding of session ID. This was an old remnant for spring remoting and has not been needed in Shiro's ThreadState mechanism for a while now. Deprecated ThreadContext methods and will remove them permanently at 1.0 final. Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/Subject.java incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/support/SubjectThreadState.java incubator/shiro/trunk/core/src/main/java/org/apache/shiro/util/ThreadContext.java Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/Subject.java URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/Subject.java?rev=896696&r1=896695&r2=896696&view=diff ============================================================================== --- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/Subject.java (original) +++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/Subject.java Wed Jan 6 22:20:38 2010 @@ -698,6 +698,38 @@ } /** + * Allows custom attributes to be added to the underlying context {@code Map} used to construct the + * {@link Subject} instance. + *

+ * A {@code null} key throws an {@link IllegalArgumentException}. A {@code null} value effectively removes + * any previously stored attribute under the given key from the context map. + *

+ * *NOTE*: This method is only useful when configuring Shiro with a custom {@link SubjectFactory} + * implementation. This method allows end-users to append additional data to the context map which the + * {@code SubjectFactory} implementation can use when building custom Subject instances. As such, this method + * is only useful when a custom {@code SubjectFactory} implementation has been configured. + * + * @see SubjectFactory#createSubject(java.util.Map) + * + * @param attributeKey the key under which the corresponding value will be stored in the context {@code Map}. + * @param attributeValue the value to store in the context map under the specified {@code attributeKey}. + * @return this {@code Builder} instance for method chaining. + * @throws IllegalArgumentException if the {@code attributeKey} is {@code null}. + */ + public Builder contextAttribute(String attributeKey, Object attributeValue) { + if (attributeKey == null) { + String msg = "Subject context map key cannot be null."; + throw new IllegalArgumentException(msg); + } + if (attributeValue == null ) { + this.subjectContext.remove(attributeKey); + } else { + this.subjectContext.put(attributeKey, attributeValue); + } + return this; + } + + /** * Creates and returns a new {@code Subject} instance reflecting the cumulative state acquired by the * other methods in this class. *

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/support/SubjectThreadState.java URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/support/SubjectThreadState.java?rev=896696&r1=896695&r2=896696&view=diff ============================================================================== --- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/support/SubjectThreadState.java (original) +++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/support/SubjectThreadState.java Wed Jan 6 22:20:38 2010 @@ -19,24 +19,19 @@ package org.apache.shiro.subject.support; import org.apache.shiro.mgt.SecurityManager; -import org.apache.shiro.session.Session; import org.apache.shiro.subject.DelegatingSubject; import org.apache.shiro.subject.Subject; import org.apache.shiro.util.ThreadContext; import org.apache.shiro.util.ThreadState; -import java.io.Serializable; - /** * @since 1.0 */ public class SubjectThreadState implements ThreadState { private Subject originalSubject; - private Serializable originalSessionId; private transient SecurityManager originalSecurityManager; - private final Serializable sessionId; private final Subject subject; private final transient SecurityManager securityManager; @@ -55,15 +50,6 @@ } else { this.securityManager = this.originalSecurityManager; } - - Session session = this.subject.getSession(false); - - this.originalSessionId = ThreadContext.getSessionId(); - if (session != null) { - this.sessionId = session.getId(); - } else { - this.sessionId = this.originalSessionId; - } } protected Subject getSubject() { @@ -71,15 +57,9 @@ } public void bind() { - this.originalSessionId = ThreadContext.getSessionId(); this.originalSubject = ThreadContext.getSubject(); this.originalSecurityManager = ThreadContext.getSecurityManager(); - if (sessionId == null) { - ThreadContext.unbindSessionId(); - } else { - ThreadContext.bindSessionId(sessionId); - } ThreadContext.bind(subject); if (securityManager == null) { ThreadContext.unbindSecurityManager(); @@ -89,11 +69,6 @@ } public void restore() { - if (originalSessionId == null) { - ThreadContext.unbindSessionId(); - } else { - ThreadContext.bindSessionId(originalSessionId); - } if (originalSubject == null) { ThreadContext.unbindSubject(); } else { Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/util/ThreadContext.java URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/util/ThreadContext.java?rev=896696&r1=896695&r2=896696&view=diff ============================================================================== --- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/util/ThreadContext.java (original) +++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/util/ThreadContext.java Wed Jan 6 22:20:38 2010 @@ -54,6 +54,10 @@ public static final String SECURITY_MANAGER_KEY = ThreadContext.class.getName() + "_SECURITY_MANAGER_KEY"; public static final String SUBJECT_KEY = ThreadContext.class.getName() + "_SUBJECT_KEY"; + /** + * @deprecated - no longer used by Shiro - will be removed prior to 1.0 final + */ + @Deprecated public static final String SESSION_ID_KEY = ThreadContext.class.getName() + "_SESSION_ID_KEY"; /** @@ -322,16 +326,28 @@ //TODO - complete JavaDoc + /** + * @deprecated - no longer used by Shiro - will be removed prior to 1.0 final + */ + @Deprecated public static Serializable getSessionId() { return (Serializable) get(SESSION_ID_KEY); } + /** + * @deprecated - no longer used by Shiro - will be removed prior to 1.0 final + */ + @Deprecated public static void bindSessionId(Serializable sessionId) { if (sessionId != null) { put(SESSION_ID_KEY, sessionId); } } + /** + * @deprecated - no longer used by Shiro - will be removed prior to 1.0 final + */ + @Deprecated public static Serializable unbindSessionId() { return (Serializable) remove(SESSION_ID_KEY);