From 22cca49d4aedab81d8183ad0fc56c567aa3988c3 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Sun, 16 Nov 2008 00:03:01 +0000 Subject: [PATCH] Added clearContext() call in @Before method. Test class appears to be failing on the build server because of a left over security context from a previous test --- .../SecuredAnnotationDrivenBeanDefinitionParserTests.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/test/java/org/springframework/security/config/SecuredAnnotationDrivenBeanDefinitionParserTests.java b/core/src/test/java/org/springframework/security/config/SecuredAnnotationDrivenBeanDefinitionParserTests.java index 457b5664a5..b32e9e1ae8 100644 --- a/core/src/test/java/org/springframework/security/config/SecuredAnnotationDrivenBeanDefinitionParserTests.java +++ b/core/src/test/java/org/springframework/security/config/SecuredAnnotationDrivenBeanDefinitionParserTests.java @@ -10,6 +10,7 @@ import org.springframework.security.GrantedAuthorityImpl; import org.springframework.security.annotation.BusinessService; import org.springframework.security.context.SecurityContextHolder; import org.springframework.security.providers.UsernamePasswordAuthenticationToken; +import org.springframework.security.util.AuthorityUtils; import org.springframework.security.util.InMemoryXmlApplicationContext; /** @@ -23,8 +24,9 @@ public class SecuredAnnotationDrivenBeanDefinitionParserTests { @Before public void loadContext() { + SecurityContextHolder.clearContext(); appContext = new InMemoryXmlApplicationContext( - "" + + "" + "" + ConfigTestUtils.AUTH_PROVIDER_XML ); target = (BusinessService) appContext.getBean("target"); @@ -46,7 +48,7 @@ public class SecuredAnnotationDrivenBeanDefinitionParserTests { @Test public void targetShouldAllowProtectedMethodInvocationWithCorrectRole() { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("Test", "Password", - new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_USER")}); + AuthorityUtils.createAuthorityList("ROLE_USER")); SecurityContextHolder.getContext().setAuthentication(token); target.someUserMethod1(); @@ -55,7 +57,7 @@ public class SecuredAnnotationDrivenBeanDefinitionParserTests { @Test(expected=AccessDeniedException.class) public void targetShouldPreventProtectedMethodInvocationWithIncorrectRole() { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("Test", "Password", - new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_SOMEOTHERROLE")}); + AuthorityUtils.createAuthorityList("ROLE_SOMEOTHER")); SecurityContextHolder.getContext().setAuthentication(token); target.someAdminMethod();