You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by lh...@apache.org on 2010/01/06 23:20:39 UTC

svn commit: r896696 - in /incubator/shiro/trunk/core/src/main/java/org/apache/shiro: subject/Subject.java subject/support/SubjectThreadState.java util/ThreadContext.java

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.
+         * <p/>
+         * 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.
+         * <p/>
+         * <b>*NOTE*:</b> 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.
          * <p/>

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);