Browse Source

Make sure test classes which are setting the context clear it in their tearDown methods.

Luke Taylor 18 years ago
parent
commit
6a6bafa219
16 changed files with 89 additions and 135 deletions
  1. 7 1
      core/src/test/java/org/acegisecurity/acls/jdbc/JdbcAclServiceTests.java
  2. 2 7
      core/src/test/java/org/acegisecurity/adapters/HttpRequestIntegrationFilterTests.java
  3. 4 4
      core/src/test/java/org/acegisecurity/context/httpinvoker/AuthenticationSimpleHttpInvokerRequestExecutorTests.java
  4. 7 7
      core/src/test/java/org/acegisecurity/context/rmi/ContextPropagatingRemoteInvocationTests.java
  5. 7 9
      core/src/test/java/org/acegisecurity/intercept/method/MethodDefinitionAttributesTests.java
  6. 8 7
      core/src/test/java/org/acegisecurity/intercept/method/aopalliance/MethodSecurityInterceptorTests.java
  7. 5 9
      core/src/test/java/org/acegisecurity/intercept/method/aspectj/AspectJSecurityInterceptorTests.java
  8. 9 22
      core/src/test/java/org/acegisecurity/intercept/web/FilterSecurityInterceptorTests.java
  9. 5 16
      core/src/test/java/org/acegisecurity/taglibs/authz/AclTagTests.java
  10. 5 4
      core/src/test/java/org/acegisecurity/taglibs/authz/AuthenticationTagTests.java
  11. 6 12
      core/src/test/java/org/acegisecurity/taglibs/authz/AuthorizeTagTests.java
  12. 7 11
      core/src/test/java/org/acegisecurity/ui/switchuser/SwitchUserProcessingFilterTests.java
  13. 1 1
      core/src/test/java/org/acegisecurity/ui/x509/X509ProcessingFilterTests.java
  14. 2 14
      core/src/test/java/org/acegisecurity/wrapper/SecurityContextHolderAwareRequestWrapperTests.java
  15. 10 11
      samples/attributes/src/test/java/sample/attributes/BankTests.java
  16. 4 0
      samples/dms/src/test/java/DmsIntegrationTests.java

+ 7 - 1
core/src/test/java/org/acegisecurity/acls/jdbc/JdbcAclServiceTests.java

@@ -58,6 +58,12 @@ public class JdbcAclServiceTests extends AbstractTransactionalDataSourceSpringCo
         this.jdbcMutableAclService = jdbcAclService;
         this.jdbcMutableAclService = jdbcAclService;
     }
     }
 
 
+
+    protected void onTearDown() throws Exception {
+        super.onTearDown();
+        SecurityContextHolder.clearContext();
+    }
+
     public void testLifecycle() {
     public void testLifecycle() {
         setComplete();
         setComplete();
 
 
@@ -159,7 +165,7 @@ public class JdbcAclServiceTests extends AbstractTransactionalDataSourceSpringCo
         // Let's add an identical permission to the child, but it'll appear AFTER the current permission, so has no impact
         // Let's add an identical permission to the child, but it'll appear AFTER the current permission, so has no impact
         child.insertAce(null, BasePermission.DELETE, new PrincipalSid(auth), true);
         child.insertAce(null, BasePermission.DELETE, new PrincipalSid(auth), true);
 
 
-        // Let's also add another permission to the child 
+        // Let's also add another permission to the child
         child.insertAce(null, BasePermission.CREATE, new PrincipalSid(auth), true);
         child.insertAce(null, BasePermission.CREATE, new PrincipalSid(auth), true);
 
 
         // Save the changed child
         // Save the changed child

+ 2 - 7
core/src/test/java/org/acegisecurity/adapters/HttpRequestIntegrationFilterTests.java

@@ -38,7 +38,6 @@ public class HttpRequestIntegrationFilterTests extends TestCase {
     //~ Constructors ===================================================================================================
     //~ Constructors ===================================================================================================
 
 
     public HttpRequestIntegrationFilterTests() {
     public HttpRequestIntegrationFilterTests() {
-        super();
     }
     }
 
 
     public HttpRequestIntegrationFilterTests(String arg0) {
     public HttpRequestIntegrationFilterTests(String arg0) {
@@ -47,18 +46,14 @@ public class HttpRequestIntegrationFilterTests extends TestCase {
 
 
     //~ Methods ========================================================================================================
     //~ Methods ========================================================================================================
 
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(HttpRequestIntegrationFilterTests.class);
-    }
-
     protected void setUp() throws Exception {
     protected void setUp() throws Exception {
         super.setUp();
         super.setUp();
-        SecurityContextHolder.getContext().setAuthentication(null);
+        SecurityContextHolder.clearContext();
     }
     }
 
 
     protected void tearDown() throws Exception {
     protected void tearDown() throws Exception {
         super.tearDown();
         super.tearDown();
-        SecurityContextHolder.getContext().setAuthentication(null);
+        SecurityContextHolder.clearContext();
     }
     }
 
 
     public void testCorrectOperation() throws Exception {
     public void testCorrectOperation() throws Exception {

+ 4 - 4
core/src/test/java/org/acegisecurity/context/httpinvoker/AuthenticationSimpleHttpInvokerRequestExecutorTests.java

@@ -52,8 +52,10 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests extends TestCas
 
 
     //~ Methods ========================================================================================================
     //~ Methods ========================================================================================================
 
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(AuthenticationSimpleHttpInvokerRequestExecutorTests.class);
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.clearContext();
     }
     }
 
 
     public void testNormalOperation() throws Exception {
     public void testNormalOperation() throws Exception {
@@ -71,8 +73,6 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests extends TestCas
         // See http://www.faqs.org/rfcs/rfc1945.html section 11.1 for example
         // See http://www.faqs.org/rfcs/rfc1945.html section 11.1 for example
         // we are comparing against
         // we are comparing against
         assertEquals("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", conn.getRequestProperty("Authorization"));
         assertEquals("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", conn.getRequestProperty("Authorization"));
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testNullContextHolderIsNull() throws Exception {
     public void testNullContextHolderIsNull() throws Exception {

+ 7 - 7
core/src/test/java/org/acegisecurity/context/rmi/ContextPropagatingRemoteInvocationTests.java

@@ -41,7 +41,6 @@ public class ContextPropagatingRemoteInvocationTests extends TestCase {
     //~ Constructors ===================================================================================================
     //~ Constructors ===================================================================================================
 
 
     public ContextPropagatingRemoteInvocationTests() {
     public ContextPropagatingRemoteInvocationTests() {
-        super();
     }
     }
 
 
     public ContextPropagatingRemoteInvocationTests(String arg0) {
     public ContextPropagatingRemoteInvocationTests(String arg0) {
@@ -50,6 +49,12 @@ public class ContextPropagatingRemoteInvocationTests extends TestCase {
 
 
     //~ Methods ========================================================================================================
     //~ Methods ========================================================================================================
 
 
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.clearContext();
+    }
+
     private ContextPropagatingRemoteInvocation getRemoteInvocation()
     private ContextPropagatingRemoteInvocation getRemoteInvocation()
         throws Exception {
         throws Exception {
         Class clazz = TargetObject.class;
         Class clazz = TargetObject.class;
@@ -61,10 +66,6 @@ public class ContextPropagatingRemoteInvocationTests extends TestCase {
         return (ContextPropagatingRemoteInvocation) factory.createRemoteInvocation(mi);
         return (ContextPropagatingRemoteInvocation) factory.createRemoteInvocation(mi);
     }
     }
 
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(ContextPropagatingRemoteInvocationTests.class);
-    }
-
     public void testContextIsResetEvenIfExceptionOccurs()
     public void testContextIsResetEvenIfExceptionOccurs()
         throws Exception {
         throws Exception {
         // Setup client-side context
         // Setup client-side context
@@ -103,8 +104,7 @@ public class ContextPropagatingRemoteInvocationTests extends TestCase {
             remoteInvocation.invoke(new TargetObject()));
             remoteInvocation.invoke(new TargetObject()));
     }
     }
 
 
-    public void testNullContextHolderDoesNotCauseInvocationProblems()
-        throws Exception {
+    public void testNullContextHolderDoesNotCauseInvocationProblems() throws Exception {
         SecurityContextHolder.getContext().setAuthentication(null); // just to be explicit
         SecurityContextHolder.getContext().setAuthentication(null); // just to be explicit
 
 
         ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
         ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();

+ 7 - 9
core/src/test/java/org/acegisecurity/intercept/method/MethodDefinitionAttributesTests.java

@@ -64,6 +64,12 @@ public class MethodDefinitionAttributesTests extends TestCase {
 
 
     //~ Methods ========================================================================================================
     //~ Methods ========================================================================================================
 
 
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.clearContext();
+    }
+
     private ConfigAttributeDefinition getConfigAttributeDefinition(Class clazz, String methodName, Class[] args)
     private ConfigAttributeDefinition getConfigAttributeDefinition(Class clazz, String methodName, Class[] args)
         throws Exception {
         throws Exception {
         final Method method = clazz.getMethod(methodName, args);
         final Method method = clazz.getMethod(methodName, args);
@@ -79,10 +85,6 @@ public class MethodDefinitionAttributesTests extends TestCase {
         return config;
         return config;
     }
     }
 
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(MethodDefinitionAttributesTests.class);
-    }
-
     private ITargetObject makeInterceptedTarget() {
     private ITargetObject makeInterceptedTarget() {
         ApplicationContext context = new ClassPathXmlApplicationContext(
         ApplicationContext context = new ClassPathXmlApplicationContext(
                 "org/acegisecurity/intercept/method/applicationContext.xml");
                 "org/acegisecurity/intercept/method/applicationContext.xml");
@@ -186,8 +188,6 @@ public class MethodDefinitionAttributesTests extends TestCase {
         ITargetObject target = makeInterceptedTarget();
         ITargetObject target = makeInterceptedTarget();
         String result = target.makeUpperCase("hello");
         String result = target.makeUpperCase("hello");
         assertEquals("HELLO org.acegisecurity.MockRunAsAuthenticationToken true", result);
         assertEquals("HELLO org.acegisecurity.MockRunAsAuthenticationToken true", result);
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testMethodCallWithoutRunAsReplacement()
     public void testMethodCallWithoutRunAsReplacement()
@@ -200,13 +200,11 @@ public class MethodDefinitionAttributesTests extends TestCase {
         String result = target.makeLowerCase("HELLO");
         String result = target.makeLowerCase("HELLO");
 
 
         assertEquals("hello org.acegisecurity.providers.UsernamePasswordAuthenticationToken true", result);
         assertEquals("hello org.acegisecurity.providers.UsernamePasswordAuthenticationToken true", result);
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testNullReturnedIfZeroAttributesDefinedForMethodInvocation()
     public void testNullReturnedIfZeroAttributesDefinedForMethodInvocation()
         throws Exception {
         throws Exception {
-        // SomeDomain is not defined in the MockAttributes() 
+        // SomeDomain is not defined in the MockAttributes()
         // (which getConfigAttributeDefinition refers to)
         // (which getConfigAttributeDefinition refers to)
         ConfigAttributeDefinition def = getConfigAttributeDefinition(SomeDomain.class, "getId", null);
         ConfigAttributeDefinition def = getConfigAttributeDefinition(SomeDomain.class, "getId", null);
         assertNull(def);
         assertNull(def);

+ 8 - 7
core/src/test/java/org/acegisecurity/intercept/method/aopalliance/MethodSecurityInterceptorTests.java

@@ -70,8 +70,14 @@ public class MethodSecurityInterceptorTests extends TestCase {
 
 
     //~ Methods ========================================================================================================
     //~ Methods ========================================================================================================
 
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(MethodSecurityInterceptorTests.class);
+    public final void setUp() throws Exception {
+        super.setUp();
+        SecurityContextHolder.clearContext();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.clearContext();
     }
     }
 
 
     private ITargetObject makeInterceptedTarget() {
     private ITargetObject makeInterceptedTarget() {
@@ -102,11 +108,6 @@ public class MethodSecurityInterceptorTests extends TestCase {
         return (ITargetObject) context.getBean("target");
         return (ITargetObject) context.getBean("target");
     }
     }
 
 
-    public final void setUp() throws Exception {
-        super.setUp();
-        SecurityContextHolder.getContext().setAuthentication(null);
-    }
-
     public void testCallingAPublicMethodFacadeWillNotRepeatSecurityChecksWhenPassedToTheSecuredMethodItFronts()
     public void testCallingAPublicMethodFacadeWillNotRepeatSecurityChecksWhenPassedToTheSecuredMethodItFronts()
         throws Exception {
         throws Exception {
         ITargetObject target = makeInterceptedTarget();
         ITargetObject target = makeInterceptedTarget();

+ 5 - 9
core/src/test/java/org/acegisecurity/intercept/method/aspectj/AspectJSecurityInterceptorTests.java

@@ -47,7 +47,6 @@ public class AspectJSecurityInterceptorTests extends TestCase {
     //~ Constructors ===================================================================================================
     //~ Constructors ===================================================================================================
 
 
     public AspectJSecurityInterceptorTests() {
     public AspectJSecurityInterceptorTests() {
-        super();
     }
     }
 
 
     public AspectJSecurityInterceptorTests(String arg0) {
     public AspectJSecurityInterceptorTests(String arg0) {
@@ -56,14 +55,15 @@ public class AspectJSecurityInterceptorTests extends TestCase {
 
 
     //~ Methods ========================================================================================================
     //~ Methods ========================================================================================================
 
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(AspectJSecurityInterceptorTests.class);
-    }
-
     public final void setUp() throws Exception {
     public final void setUp() throws Exception {
         super.setUp();
         super.setUp();
     }
     }
 
 
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.clearContext();
+    }    
+
     public void testCallbackIsInvokedWhenPermissionGranted()
     public void testCallbackIsInvokedWhenPermissionGranted()
         throws Exception {
         throws Exception {
         AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
         AspectJSecurityInterceptor si = new AspectJSecurityInterceptor();
@@ -94,8 +94,6 @@ public class AspectJSecurityInterceptorTests extends TestCase {
         Object result = si.invoke(joinPoint, aspectJCallback);
         Object result = si.invoke(joinPoint, aspectJCallback);
 
 
         assertEquals("object proceeded", result);
         assertEquals("object proceeded", result);
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testCallbackIsNotInvokedWhenPermissionDenied()
     public void testCallbackIsNotInvokedWhenPermissionDenied()
@@ -131,8 +129,6 @@ public class AspectJSecurityInterceptorTests extends TestCase {
         } catch (AccessDeniedException expected) {
         } catch (AccessDeniedException expected) {
             assertTrue(true);
             assertTrue(true);
         }
         }
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     //~ Inner Classes ==================================================================================================
     //~ Inner Classes ==================================================================================================

+ 9 - 22
core/src/test/java/org/acegisecurity/intercept/web/FilterSecurityInterceptorTests.java

@@ -57,7 +57,6 @@ public class FilterSecurityInterceptorTests extends TestCase {
     //~ Constructors ===================================================================================================
     //~ Constructors ===================================================================================================
 
 
     public FilterSecurityInterceptorTests() {
     public FilterSecurityInterceptorTests() {
-        super();
     }
     }
 
 
     public FilterSecurityInterceptorTests(String arg0) {
     public FilterSecurityInterceptorTests(String arg0) {
@@ -66,12 +65,14 @@ public class FilterSecurityInterceptorTests extends TestCase {
 
 
     //~ Methods ========================================================================================================
     //~ Methods ========================================================================================================
 
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(FilterSecurityInterceptorTests.class);
-    }
-
     public final void setUp() throws Exception {
     public final void setUp() throws Exception {
         super.setUp();
         super.setUp();
+        SecurityContextHolder.clearContext();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        SecurityContextHolder.clearContext();
     }
     }
 
 
     public void testEnsuresAccessDecisionManagerSupportsFilterInvocationClass()
     public void testEnsuresAccessDecisionManagerSupportsFilterInvocationClass()
@@ -136,8 +137,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
         }
         }
     }
     }
 
 
-    public void testHttpsInvocationReflectsPortNumber()
-        throws Throwable {
+    public void testHttpsInvocationReflectsPortNumber() throws Throwable {
         // Setup the FilterSecurityInterceptor
         // Setup the FilterSecurityInterceptor
         FilterSecurityInterceptor interceptor = new FilterSecurityInterceptor();
         FilterSecurityInterceptor interceptor = new FilterSecurityInterceptor();
         interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
         interceptor.setAccessDecisionManager(new MockAccessDecisionManager());
@@ -170,9 +170,6 @@ public class FilterSecurityInterceptorTests extends TestCase {
         // Create and test our secure object
         // Create and test our secure object
         FilterInvocation fi = new FilterInvocation(request, response, chain);
         FilterInvocation fi = new FilterInvocation(request, response, chain);
         interceptor.invoke(fi);
         interceptor.invoke(fi);
-
-        // Destroy the Context
-        SecurityContextHolder.clearContext();
     }
     }
 
 
     public void testNormalStartupAndGetter() throws Exception {
     public void testNormalStartupAndGetter() throws Exception {
@@ -225,9 +222,6 @@ public class FilterSecurityInterceptorTests extends TestCase {
         // Create and test our secure object
         // Create and test our secure object
         FilterInvocation fi = new FilterInvocation(request, response, chain);
         FilterInvocation fi = new FilterInvocation(request, response, chain);
         interceptor.invoke(fi);
         interceptor.invoke(fi);
-
-        // Destroy the Context
-        SecurityContextHolder.clearContext();
     }
     }
 
 
     public void testNotLoadedFromApplicationContext() throws Exception {
     public void testNotLoadedFromApplicationContext() throws Exception {
@@ -239,8 +233,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
         mappings.add(mapping);
         mappings.add(mapping);
 
 
         PathBasedFilterInvocationDefinitionMap filterInvocationDefinitionSource = new PathBasedFilterInvocationDefinitionMap();
         PathBasedFilterInvocationDefinitionMap filterInvocationDefinitionSource = new PathBasedFilterInvocationDefinitionMap();
-        filterInvocationDefinitionSource
-                .setConvertUrlToLowercaseBeforeComparison(true);
+        filterInvocationDefinitionSource.setConvertUrlToLowercaseBeforeComparison(true);
         FilterInvocationDefinitionDecorator decorator = new FilterInvocationDefinitionDecorator(
         FilterInvocationDefinitionDecorator decorator = new FilterInvocationDefinitionDecorator(
                 filterInvocationDefinitionSource);
                 filterInvocationDefinitionSource);
         decorator.setMappings(mappings);
         decorator.setMappings(mappings);
@@ -252,8 +245,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
         filterChain.expectToProceed = true;
         filterChain.expectToProceed = true;
 
 
         FilterInvocation fi = new FilterInvocation(
         FilterInvocation fi = new FilterInvocation(
-                new MockHttpServletRequest(), new MockHttpServletResponse(),
-                filterChain);
+                new MockHttpServletRequest(), new MockHttpServletResponse(), filterChain);
         filter.invoke(fi);
         filter.invoke(fi);
     }
     }
 
 
@@ -267,7 +259,6 @@ public class FilterSecurityInterceptorTests extends TestCase {
         }
         }
 
 
         private MockFilterChain() {
         private MockFilterChain() {
-            super();
         }
         }
 
 
         public void doFilter(ServletRequest request, ServletResponse response)
         public void doFilter(ServletRequest request, ServletResponse response)
@@ -289,10 +280,6 @@ public class FilterSecurityInterceptorTests extends TestCase {
             this.toReturn = toReturn;
             this.toReturn = toReturn;
         }
         }
 
 
-        private MockFilterInvocationDefinitionMap() {
-            super();
-        }
-
         public ConfigAttributeDefinition getAttributes(Object object)
         public ConfigAttributeDefinition getAttributes(Object object)
             throws IllegalArgumentException {
             throws IllegalArgumentException {
             FilterInvocation fi = (FilterInvocation) object;
             FilterInvocation fi = (FilterInvocation) object;

+ 5 - 16
core/src/test/java/org/acegisecurity/taglibs/authz/AclTagTests.java

@@ -52,6 +52,11 @@ public class AclTagTests extends TestCase {
 
 
     //~ Methods ========================================================================================================
     //~ Methods ========================================================================================================
 
 
+
+    protected void tearDown() throws Exception {
+        SecurityContextHolder.clearContext();
+    }
+
     public void testInclusionDeniedWhenAclManagerUnawareOfObject()
     public void testInclusionDeniedWhenAclManagerUnawareOfObject()
         throws JspException {
         throws JspException {
         Authentication auth = new TestingAuthenticationToken("marissa", "koala", new GrantedAuthority[] {});
         Authentication auth = new TestingAuthenticationToken("marissa", "koala", new GrantedAuthority[] {});
@@ -60,8 +65,6 @@ public class AclTagTests extends TestCase {
         aclTag.setHasPermission(new Long(SimpleAclEntry.ADMINISTRATION).toString());
         aclTag.setHasPermission(new Long(SimpleAclEntry.ADMINISTRATION).toString());
         aclTag.setDomainObject(new Integer(54));
         aclTag.setDomainObject(new Integer(54));
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testInclusionDeniedWhenNoListOfPermissionsGiven()
     public void testInclusionDeniedWhenNoListOfPermissionsGiven()
@@ -72,8 +75,6 @@ public class AclTagTests extends TestCase {
         aclTag.setHasPermission(null);
         aclTag.setHasPermission(null);
         aclTag.setDomainObject("object1");
         aclTag.setDomainObject("object1");
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testInclusionDeniedWhenPrincipalDoesNotHoldAnyPermissions()
     public void testInclusionDeniedWhenPrincipalDoesNotHoldAnyPermissions()
@@ -87,8 +88,6 @@ public class AclTagTests extends TestCase {
         aclTag.setDomainObject("object1");
         aclTag.setDomainObject("object1");
         assertEquals("object1", aclTag.getDomainObject());
         assertEquals("object1", aclTag.getDomainObject());
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testInclusionDeniedWhenPrincipalDoesNotHoldRequiredPermissions()
     public void testInclusionDeniedWhenPrincipalDoesNotHoldRequiredPermissions()
@@ -99,8 +98,6 @@ public class AclTagTests extends TestCase {
         aclTag.setHasPermission(new Integer(SimpleAclEntry.DELETE).toString());
         aclTag.setHasPermission(new Integer(SimpleAclEntry.DELETE).toString());
         aclTag.setDomainObject("object1");
         aclTag.setDomainObject("object1");
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testInclusionDeniedWhenSecurityContextEmpty()
     public void testInclusionDeniedWhenSecurityContextEmpty()
@@ -110,8 +107,6 @@ public class AclTagTests extends TestCase {
         aclTag.setHasPermission(new Long(SimpleAclEntry.ADMINISTRATION).toString());
         aclTag.setHasPermission(new Long(SimpleAclEntry.ADMINISTRATION).toString());
         aclTag.setDomainObject("object1");
         aclTag.setDomainObject("object1");
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
         assertEquals(Tag.SKIP_BODY, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testInclusionPermittedWhenDomainObjectIsNull()
     public void testInclusionPermittedWhenDomainObjectIsNull()
@@ -134,8 +129,6 @@ public class AclTagTests extends TestCase {
         } catch (JspException expected) {
         } catch (JspException expected) {
             assertTrue(true);
             assertTrue(true);
         }
         }
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testOperationWhenPrincipalHoldsPermissionOfMultipleList()
     public void testOperationWhenPrincipalHoldsPermissionOfMultipleList()
@@ -146,8 +139,6 @@ public class AclTagTests extends TestCase {
         aclTag.setHasPermission(new Integer(SimpleAclEntry.ADMINISTRATION) + "," + new Integer(SimpleAclEntry.READ));
         aclTag.setHasPermission(new Integer(SimpleAclEntry.ADMINISTRATION) + "," + new Integer(SimpleAclEntry.READ));
         aclTag.setDomainObject("object1");
         aclTag.setDomainObject("object1");
         assertEquals(Tag.EVAL_BODY_INCLUDE, aclTag.doStartTag());
         assertEquals(Tag.EVAL_BODY_INCLUDE, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testOperationWhenPrincipalHoldsPermissionOfSingleList()
     public void testOperationWhenPrincipalHoldsPermissionOfSingleList()
@@ -158,8 +149,6 @@ public class AclTagTests extends TestCase {
         aclTag.setHasPermission(new Integer(SimpleAclEntry.READ).toString());
         aclTag.setHasPermission(new Integer(SimpleAclEntry.READ).toString());
         aclTag.setDomainObject("object1");
         aclTag.setDomainObject("object1");
         assertEquals(Tag.EVAL_BODY_INCLUDE, aclTag.doStartTag());
         assertEquals(Tag.EVAL_BODY_INCLUDE, aclTag.doStartTag());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     //~ Inner Classes ==================================================================================================
     //~ Inner Classes ==================================================================================================

+ 5 - 4
core/src/test/java/org/acegisecurity/taglibs/authz/AuthenticationTagTests.java

@@ -43,6 +43,10 @@ public class AuthenticationTagTests extends TestCase {
 
 
     //~ Methods ========================================================================================================
     //~ Methods ========================================================================================================
 
 
+    protected void tearDown() throws Exception {
+        SecurityContextHolder.clearContext();
+    }
+
     public void testOperationAndMethodPrefixWhenPrincipalIsAUserDetailsInstance()
     public void testOperationAndMethodPrefixWhenPrincipalIsAUserDetailsInstance()
         throws JspException {
         throws JspException {
         Authentication auth = new TestingAuthenticationToken(new User("marissaUserDetails", "koala", true, true, true,
         Authentication auth = new TestingAuthenticationToken(new User("marissaUserDetails", "koala", true, true, true,
@@ -83,15 +87,12 @@ public class AuthenticationTagTests extends TestCase {
         assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
         assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
     }
     }
 
 
-    public void testOperationWhenSecurityContextIsNull()
-        throws JspException {
+    public void testOperationWhenSecurityContextIsNull() throws Exception {
         SecurityContextHolder.getContext().setAuthentication(null);
         SecurityContextHolder.getContext().setAuthentication(null);
 
 
         authenticationTag.setOperation("principal");
         authenticationTag.setOperation("principal");
         assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
         assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
         assertEquals(null, authenticationTag.getLastMessage());
         assertEquals(null, authenticationTag.getLastMessage());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testSkipsBodyIfNullOrEmptyOperation() throws Exception {
     public void testSkipsBodyIfNullOrEmptyOperation() throws Exception {

+ 6 - 12
core/src/test/java/org/acegisecurity/taglibs/authz/AuthorizeTagTests.java

@@ -57,16 +57,14 @@ public class AuthorizeTagTests extends TestCase {
         SecurityContextHolder.clearContext();
         SecurityContextHolder.clearContext();
     }
     }
 
 
-    public void testAlwaysReturnsUnauthorizedIfNoUserFound()
-        throws JspException {
+    public void testAlwaysReturnsUnauthorizedIfNoUserFound() throws JspException {
         SecurityContextHolder.getContext().setAuthentication(null);
         SecurityContextHolder.getContext().setAuthentication(null);
 
 
         authorizeTag.setIfAllGranted("ROLE_TELLER");
         authorizeTag.setIfAllGranted("ROLE_TELLER");
         assertEquals("prevents request - no principal in Context", Tag.SKIP_BODY, authorizeTag.doStartTag());
         assertEquals("prevents request - no principal in Context", Tag.SKIP_BODY, authorizeTag.doStartTag());
     }
     }
 
 
-    public void testDefaultsToNotOutputtingBodyWhenNoRequiredAuthorities()
-        throws JspException {
+    public void testDefaultsToNotOutputtingBodyWhenNoRequiredAuthorities() throws JspException {
         assertEquals("", authorizeTag.getIfAllGranted());
         assertEquals("", authorizeTag.getIfAllGranted());
         assertEquals("", authorizeTag.getIfAnyGranted());
         assertEquals("", authorizeTag.getIfAnyGranted());
         assertEquals("", authorizeTag.getIfNotGranted());
         assertEquals("", authorizeTag.getIfNotGranted());
@@ -85,15 +83,13 @@ public class AuthorizeTagTests extends TestCase {
             authorizeTag.doStartTag());
             authorizeTag.doStartTag());
     }
     }
 
 
-    public void testOutputsBodyWhenNotGrantedSatisfied()
-        throws JspException {
+    public void testOutputsBodyWhenNotGrantedSatisfied() throws JspException {
         authorizeTag.setIfNotGranted("ROLE_BANKER");
         authorizeTag.setIfNotGranted("ROLE_BANKER");
         assertEquals("allows request - principal doesn't have ROLE_BANKER", Tag.EVAL_BODY_INCLUDE,
         assertEquals("allows request - principal doesn't have ROLE_BANKER", Tag.EVAL_BODY_INCLUDE,
             authorizeTag.doStartTag());
             authorizeTag.doStartTag());
     }
     }
 
 
-    public void testPreventsBodyOutputIfNoSecurityContext()
-        throws JspException {
+    public void testPreventsBodyOutputIfNoSecurityContext() throws JspException {
         SecurityContextHolder.getContext().setAuthentication(null);
         SecurityContextHolder.getContext().setAuthentication(null);
         authorizeTag.setIfAnyGranted("ROLE_BANKER");
         authorizeTag.setIfAnyGranted("ROLE_BANKER");
 
 
@@ -105,14 +101,12 @@ public class AuthorizeTagTests extends TestCase {
         assertEquals("unauthorized - ROLE_BANKER not in granted authorities", Tag.SKIP_BODY, authorizeTag.doStartTag());
         assertEquals("unauthorized - ROLE_BANKER not in granted authorities", Tag.SKIP_BODY, authorizeTag.doStartTag());
     }
     }
 
 
-    public void testSkipsBodyWhenMissingAnAllGranted()
-        throws JspException {
+    public void testSkipsBodyWhenMissingAnAllGranted() throws JspException {
         authorizeTag.setIfAllGranted("ROLE SUPERVISOR,ROLE_TELLER,ROLE_BANKER");
         authorizeTag.setIfAllGranted("ROLE SUPERVISOR,ROLE_TELLER,ROLE_BANKER");
         assertEquals("prevents request - missing ROLE_BANKER on principal", Tag.SKIP_BODY, authorizeTag.doStartTag());
         assertEquals("prevents request - missing ROLE_BANKER on principal", Tag.SKIP_BODY, authorizeTag.doStartTag());
     }
     }
 
 
-    public void testSkipsBodyWhenNotGrantedUnsatisfied()
-        throws JspException {
+    public void testSkipsBodyWhenNotGrantedUnsatisfied() throws JspException {
         authorizeTag.setIfNotGranted("ROLE_TELLER");
         authorizeTag.setIfNotGranted("ROLE_TELLER");
         assertEquals("prevents request - principal has ROLE_TELLER", Tag.SKIP_BODY, authorizeTag.doStartTag());
         assertEquals("prevents request - principal has ROLE_TELLER", Tag.SKIP_BODY, authorizeTag.doStartTag());
     }
     }

+ 7 - 11
core/src/test/java/org/acegisecurity/ui/switchuser/SwitchUserProcessingFilterTests.java

@@ -52,7 +52,6 @@ public class SwitchUserProcessingFilterTests extends TestCase {
     //~ Constructors ===================================================================================================
     //~ Constructors ===================================================================================================
 
 
     public SwitchUserProcessingFilterTests() {
     public SwitchUserProcessingFilterTests() {
-        super();
     }
     }
 
 
     public SwitchUserProcessingFilterTests(String arg0) {
     public SwitchUserProcessingFilterTests(String arg0) {
@@ -61,6 +60,11 @@ public class SwitchUserProcessingFilterTests extends TestCase {
 
 
     //~ Methods ========================================================================================================
     //~ Methods ========================================================================================================
 
 
+
+    protected void tearDown() throws Exception {
+        SecurityContextHolder.clearContext();
+    }
+
     private MockHttpServletRequest createMockSwitchRequest() {
     private MockHttpServletRequest createMockSwitchRequest() {
         MockHttpServletRequest request = new MockHttpServletRequest();
         MockHttpServletRequest request = new MockHttpServletRequest();
         request.setScheme("http");
         request.setScheme("http");
@@ -70,14 +74,6 @@ public class SwitchUserProcessingFilterTests extends TestCase {
         return request;
         return request;
     }
     }
 
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(SwitchUserProcessingFilterTests.class);
-    }
-
-    public final void setUp() throws Exception {
-        super.setUp();
-    }
-
     public void testAttemptSwitchToUnknownUser() throws Exception {
     public void testAttemptSwitchToUnknownUser() throws Exception {
         // set current user
         // set current user
         UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("dano", "hawaii50");
         UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("dano", "hawaii50");
@@ -179,7 +175,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
         Authentication result = filter.attemptSwitchUser(request);
         Authentication result = filter.attemptSwitchUser(request);
         assertTrue(result != null);
         assertTrue(result != null);
     }
     }
-    
+
     public void testIfSwitchUserWithNullUsernameThrowsException() throws Exception {
     public void testIfSwitchUserWithNullUsernameThrowsException() throws Exception {
         // set current user
         // set current user
         UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("dano", "hawaii50");
         UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("dano", "hawaii50");
@@ -196,7 +192,7 @@ public class SwitchUserProcessingFilterTests extends TestCase {
         	 result = filter.attemptSwitchUser(request);
         	 result = filter.attemptSwitchUser(request);
         	 fail("UsernameNotFoundException should have been thrown");
         	 fail("UsernameNotFoundException should have been thrown");
         } catch (UsernameNotFoundException e) {
         } catch (UsernameNotFoundException e) {
-        	
+
         }
         }
         assertFalse(result != null);
         assertFalse(result != null);
     }
     }

+ 1 - 1
core/src/test/java/org/acegisecurity/ui/x509/X509ProcessingFilterTests.java

@@ -64,7 +64,7 @@ public class X509ProcessingFilterTests extends TestCase {
     }
     }
 
 
     public void tearDown() {
     public void tearDown() {
-        SecurityContextHolder.getContext().setAuthentication(null);
+        SecurityContextHolder.clearContext();
     }
     }
 
 
     public void testAuthenticationIsNullWithNoCertificate()
     public void testAuthenticationIsNullWithNoCertificate()

+ 2 - 14
core/src/test/java/org/acegisecurity/wrapper/SecurityContextHolderAwareRequestWrapperTests.java

@@ -37,7 +37,6 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
     //~ Constructors ===================================================================================================
     //~ Constructors ===================================================================================================
 
 
     public SecurityContextHolderAwareRequestWrapperTests() {
     public SecurityContextHolderAwareRequestWrapperTests() {
-        super();
     }
     }
 
 
     public SecurityContextHolderAwareRequestWrapperTests(String arg0) {
     public SecurityContextHolderAwareRequestWrapperTests(String arg0) {
@@ -46,12 +45,9 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
 
 
     //~ Methods ========================================================================================================
     //~ Methods ========================================================================================================
 
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(SecurityContextHolderAwareRequestWrapperTests.class);
-    }
 
 
-    public final void setUp() throws Exception {
-        super.setUp();
+    protected void tearDown() throws Exception {
+        SecurityContextHolder.clearContext();
     }
     }
 
 
     public void testCorrectOperationWithStringBasedPrincipal()
     public void testCorrectOperationWithStringBasedPrincipal()
@@ -69,8 +65,6 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
         assertTrue(wrapper.isUserInRole("ROLE_FOO"));
         assertTrue(wrapper.isUserInRole("ROLE_FOO"));
         assertFalse(wrapper.isUserInRole("ROLE_NOT_GRANTED"));
         assertFalse(wrapper.isUserInRole("ROLE_NOT_GRANTED"));
         assertEquals(auth, wrapper.getUserPrincipal());
         assertEquals(auth, wrapper.getUserPrincipal());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testCorrectOperationWithUserDetailsBasedPrincipal()
     public void testCorrectOperationWithUserDetailsBasedPrincipal()
@@ -91,8 +85,6 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
         assertTrue(wrapper.isUserInRole("ROLE_FOOBAR"));
         assertTrue(wrapper.isUserInRole("ROLE_FOOBAR"));
         assertTrue(wrapper.isUserInRole("ROLE_HELLO"));
         assertTrue(wrapper.isUserInRole("ROLE_HELLO"));
         assertEquals(auth, wrapper.getUserPrincipal());
         assertEquals(auth, wrapper.getUserPrincipal());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testNullAuthenticationHandling() throws Exception {
     public void testNullAuthenticationHandling() throws Exception {
@@ -105,8 +97,6 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
         assertNull(wrapper.getRemoteUser());
         assertNull(wrapper.getRemoteUser());
         assertFalse(wrapper.isUserInRole("ROLE_ANY"));
         assertFalse(wrapper.isUserInRole("ROLE_ANY"));
         assertNull(wrapper.getUserPrincipal());
         assertNull(wrapper.getUserPrincipal());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 
 
     public void testNullPrincipalHandling() throws Exception {
     public void testNullPrincipalHandling() throws Exception {
@@ -123,7 +113,5 @@ public class SecurityContextHolderAwareRequestWrapperTests extends TestCase {
         assertFalse(wrapper.isUserInRole("ROLE_HELLO")); // principal is null, so reject
         assertFalse(wrapper.isUserInRole("ROLE_HELLO")); // principal is null, so reject
         assertFalse(wrapper.isUserInRole("ROLE_FOOBAR")); // principal is null, so reject
         assertFalse(wrapper.isUserInRole("ROLE_FOOBAR")); // principal is null, so reject
         assertNull(wrapper.getUserPrincipal());
         assertNull(wrapper.getUserPrincipal());
-
-        SecurityContextHolder.getContext().setAuthentication(null);
     }
     }
 }
 }

+ 10 - 11
samples/attributes/src/test/java/sample/attributes/BankTests.java

@@ -44,7 +44,6 @@ public class BankTests extends TestCase {
     //~ Constructors ===================================================================================================
     //~ Constructors ===================================================================================================
 
 
     public BankTests() {
     public BankTests() {
-        super();
     }
     }
 
 
     public BankTests(String arg0) {
     public BankTests(String arg0) {
@@ -53,6 +52,16 @@ public class BankTests extends TestCase {
 
 
     //~ Methods ========================================================================================================
     //~ Methods ========================================================================================================
 
 
+    public final void setUp() throws Exception {
+        super.setUp();
+        ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
+        service = (BankService) ctx.getBean("bankService");
+    }
+
+    public void tearDown() {
+        SecurityContextHolder.clearContext();
+    }
+
     private static void createSecureContext() {
     private static void createSecureContext() {
         TestingAuthenticationToken auth = new TestingAuthenticationToken("test", "test",
         TestingAuthenticationToken auth = new TestingAuthenticationToken("test", "test",
                 new GrantedAuthority[] {
                 new GrantedAuthority[] {
@@ -66,16 +75,6 @@ public class BankTests extends TestCase {
         SecurityContextHolder.setContext(new SecurityContextImpl());
         SecurityContextHolder.setContext(new SecurityContextImpl());
     }
     }
 
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(BankTests.class);
-    }
-
-    public final void setUp() throws Exception {
-        super.setUp();
-        ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
-        service = (BankService) ctx.getBean("bankService");
-    }
-
     public void testDeniedAccess() throws Exception {
     public void testDeniedAccess() throws Exception {
         createSecureContext();
         createSecureContext();
 
 

+ 4 - 0
samples/dms/src/test/java/DmsIntegrationTests.java

@@ -20,6 +20,10 @@ public class DmsIntegrationTests extends AbstractTransactionalDataSourceSpringCo
         return new String[] {"classpath:applicationContext-dms-shared.xml", "classpath:applicationContext-dms-insecure.xml"};
         return new String[] {"classpath:applicationContext-dms-shared.xml", "classpath:applicationContext-dms-insecure.xml"};
     }
     }
 
 
+    public void tearDown() {
+        SecurityContextHolder.clearContext();
+    }
+
     public void setDocumentDao(DocumentDao documentDao) {
     public void setDocumentDao(DocumentDao documentDao) {
         this.documentDao = documentDao;
         this.documentDao = documentDao;
     }
     }