shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdem...@apache.org
Subject shiro git commit: Revert "SHIRO-391 -- ThreadContext.bind(Subject) also binds the subject's primary principal to slf4j's MDC"
Date Thu, 10 Nov 2016 20:56:55 GMT
Repository: shiro
Updated Branches:
  refs/heads/master 2606a3876 -> 3c6afaf05


Revert "SHIRO-391 -- ThreadContext.bind(Subject) also binds the subject's primary principal
to slf4j's MDC"

This reverts commit ccdf4c3ec53c210fce4705b816282b5eb7dec1eb.


Project: http://git-wip-us.apache.org/repos/asf/shiro/repo
Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/3c6afaf0
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/3c6afaf0
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/3c6afaf0

Branch: refs/heads/master
Commit: 3c6afaf0560fb7c91f94f2bbc9679b12c951fb52
Parents: 2606a38
Author: Brian Demers <bdemers@apache.org>
Authored: Thu Nov 10 15:38:36 2016 -0500
Committer: Brian Demers <bdemers@apache.org>
Committed: Thu Nov 10 15:54:47 2016 -0500

----------------------------------------------------------------------
 .../org/apache/shiro/util/ThreadContext.java    |  9 -------
 .../shiro/guice/ShiroSessionScopeTest.java      |  6 ++---
 .../web/jaxrs/ShiroSecurityContextTest.groovy   | 27 +++++---------------
 3 files changed, 9 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/shiro/blob/3c6afaf0/core/src/main/java/org/apache/shiro/util/ThreadContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/shiro/util/ThreadContext.java b/core/src/main/java/org/apache/shiro/util/ThreadContext.java
index 53057d7..28488a3 100644
--- a/core/src/main/java/org/apache/shiro/util/ThreadContext.java
+++ b/core/src/main/java/org/apache/shiro/util/ThreadContext.java
@@ -22,7 +22,6 @@ import org.apache.shiro.mgt.SecurityManager;
 import org.apache.shiro.subject.Subject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
 
 import java.util.Collections;
 import java.util.HashMap;
@@ -54,12 +53,6 @@ public abstract class ThreadContext {
     public static final String SECURITY_MANAGER_KEY = ThreadContext.class.getName() + "_SECURITY_MANAGER_KEY";
     public static final String SUBJECT_KEY = ThreadContext.class.getName() + "_SUBJECT_KEY";
 
-	/**
-     * The key of the subject in SLF4Js Mapped Diagnostic Context ({@link MDC}). This can
be used to
-     * show the subject in the logs. The subject is displayed in the logs using the pattern
<pre>%X{shiroSubject}</pre>.
-     */
-    private static final String SUBJECT_KEY_MDC = "shiroSubject";
-
     private static final ThreadLocal<Map<Object, Object>> resources = new InheritableThreadLocalMap<Map<Object,
Object>>();
 
     /**
@@ -307,7 +300,6 @@ public abstract class ThreadContext {
     public static void bind(Subject subject) {
         if (subject != null) {
             put(SUBJECT_KEY, subject);
-            MDC.put(SUBJECT_KEY_MDC, String.valueOf(subject.getPrincipal()));
         }
     }
 
@@ -326,7 +318,6 @@ public abstract class ThreadContext {
      * @since 0.2
      */
     public static Subject unbindSubject() {
-        MDC.remove(SUBJECT_KEY_MDC);
         return (Subject) remove(SUBJECT_KEY);
     }
     

http://git-wip-us.apache.org/repos/asf/shiro/blob/3c6afaf0/support/guice/src/test/java/org/apache/shiro/guice/ShiroSessionScopeTest.java
----------------------------------------------------------------------
diff --git a/support/guice/src/test/java/org/apache/shiro/guice/ShiroSessionScopeTest.java
b/support/guice/src/test/java/org/apache/shiro/guice/ShiroSessionScopeTest.java
index 4c70824..9b8c901 100644
--- a/support/guice/src/test/java/org/apache/shiro/guice/ShiroSessionScopeTest.java
+++ b/support/guice/src/test/java/org/apache/shiro/guice/ShiroSessionScopeTest.java
@@ -34,14 +34,14 @@ public class ShiroSessionScopeTest {
     public void testScope() throws Exception {
         Subject subject = createMock(Subject.class);
         try {
+            ThreadContext.bind(subject);
+
             final Key<SomeClass> key = Key.get(SomeClass.class);
             Provider<SomeClass> mockProvider = createMock(Provider.class);
             Session session = createMock(Session.class);
 
             SomeClass retuned = new SomeClass();
 
-            expect(subject.getPrincipal()).andReturn("testUser").anyTimes();
-
             expect(subject.getSession()).andReturn(session);
             expect(session.getAttribute(key)).andReturn(null);
             expect(mockProvider.get()).andReturn(retuned);
@@ -52,8 +52,6 @@ public class ShiroSessionScopeTest {
 
             replay(subject, mockProvider, session);
 
-            ThreadContext.bind(subject);
-
             ShiroSessionScope underTest = new ShiroSessionScope();
 
             // first time the session doesn't contain it, we expect the provider to be invoked

http://git-wip-us.apache.org/repos/asf/shiro/blob/3c6afaf0/support/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ShiroSecurityContextTest.groovy
----------------------------------------------------------------------
diff --git a/support/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ShiroSecurityContextTest.groovy
b/support/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ShiroSecurityContextTest.groovy
index b2c0c96..5d7e947 100644
--- a/support/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ShiroSecurityContextTest.groovy
+++ b/support/jaxrs/src/test/groovy/org/apache/shiro/web/jaxrs/ShiroSecurityContextTest.groovy
@@ -73,15 +73,13 @@ class ShiroSecurityContextTest {
         def originalSecurityContext = mock(SecurityContext)
         def shrioContext = new ShiroSecurityContext(requestContext)
         def subject = mock(Subject)
+        ThreadContext.bind(subject)
 
-        expect(subject.getPrincipal()).andReturn("TestUser")
         expect(requestContext.getSecurityContext()).andReturn(originalSecurityContext).anyTimes()
         expect(subject.getPrincipals()).andReturn(new SimplePrincipalCollection("TestUser",
"realm"))
 
         replay requestContext, originalSecurityContext, subject
 
-        ThreadContext.bind(subject)
-
         def resultPrincipal = shrioContext.getUserPrincipal()
         assertSame "TestUser", resultPrincipal.getName()
 
@@ -94,16 +92,14 @@ class ShiroSecurityContextTest {
         def originalSecurityContext = mock(SecurityContext)
         def shrioContext = new ShiroSecurityContext(requestContext)
         def subject = mock(Subject)
+        ThreadContext.bind(subject)
 
-        expect(subject.getPrincipal()).andReturn(null)
         expect(requestContext.getSecurityContext()).andReturn(originalSecurityContext).anyTimes()
         expect(subject.getPrincipals()).andReturn(null)
         expect(originalSecurityContext.getUserPrincipal()).andReturn(null)
 
         replay requestContext, originalSecurityContext, subject
 
-        ThreadContext.bind(subject)
-
         assertNull shrioContext.getUserPrincipal()
 
         verify requestContext, originalSecurityContext, subject
@@ -115,16 +111,13 @@ class ShiroSecurityContextTest {
         def originalSecurityContext = mock(SecurityContext)
         def shrioContext = new ShiroSecurityContext(requestContext)
         def subject = mock(Subject)
-        def testPrincipal = new TestPrincipal("Tester")
+        ThreadContext.bind(subject)
 
-        expect(subject.getPrincipal()).andReturn(testPrincipal)
         expect(requestContext.getSecurityContext()).andReturn(originalSecurityContext).anyTimes()
-        expect(subject.getPrincipals()).andReturn(new SimplePrincipalCollection(testPrincipal,
"test-realm"))
+        expect(subject.getPrincipals()).andReturn(new SimplePrincipalCollection(new TestPrincipal("Tester"),
"test-realm"))
 
         replay requestContext, originalSecurityContext, subject
 
-        ThreadContext.bind(subject)
-
         def resultPrincipal = shrioContext.getUserPrincipal()
         assertSame "Tester", resultPrincipal.getName()
 
@@ -137,15 +130,13 @@ class ShiroSecurityContextTest {
         def originalSecurityContext = mock(SecurityContext)
         def shrioContext = new ShiroSecurityContext(requestContext)
         def subject = mock(Subject)
+        ThreadContext.bind(subject)
 
-        expect(subject.getPrincipal()).andReturn("test-principal")
         expect(requestContext.getSecurityContext()).andReturn(originalSecurityContext).anyTimes()
         expect(subject.hasRole("test-role")).andReturn(true)
 
         replay requestContext, originalSecurityContext, subject
 
-        ThreadContext.bind(subject)
-
         assertTrue shrioContext.isUserInRole("test-role")
 
         verify requestContext, originalSecurityContext, subject
@@ -157,15 +148,13 @@ class ShiroSecurityContextTest {
         def originalSecurityContext = mock(SecurityContext)
         def shrioContext = new ShiroSecurityContext(requestContext)
         def subject = mock(Subject)
+        ThreadContext.bind(subject)
 
-        expect(subject.getPrincipal()).andReturn("test-principal")
         expect(requestContext.getSecurityContext()).andReturn(originalSecurityContext).anyTimes()
         expect(subject.hasRole("test-role")).andReturn(false)
 
         replay requestContext, originalSecurityContext, subject
 
-        ThreadContext.bind(subject)
-
         assertFalse shrioContext.isUserInRole("test-role")
 
         verify requestContext, originalSecurityContext, subject
@@ -177,16 +166,14 @@ class ShiroSecurityContextTest {
         def originalSecurityContext = mock(SecurityContext)
         def shrioContext = new ShiroSecurityContext(requestContext)
         def subject = mock(Subject)
+        ThreadContext.bind(subject)
 
-        expect(subject.getPrincipal()).andReturn(null) // we are just testing equality here
         expect(requestContext.getSecurityContext()).andReturn(originalSecurityContext).anyTimes()
         expect(subject.getPrincipals()).andReturn(new SimplePrincipalCollection("Tester",
"test-realm"))
         expect(subject.getPrincipals()).andReturn(new SimplePrincipalCollection("Tester",
"test-realm"))
 
         replay requestContext, originalSecurityContext, subject
 
-        ThreadContext.bind(subject)
-
         def result1Principal = shrioContext.getUserPrincipal()
         def result2Principal = shrioContext.getUserPrincipal()
 


Mime
View raw message