mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-10-30 22:28:46 +00:00 
			
		
		
		
	Refactor to use Spring's MockHttpServletRequest rather than Acegi Security's equivalent.
This commit is contained in:
		
							parent
							
								
									b26183dc66
								
							
						
					
					
						commit
						35cdd24abf
					
				| @ -17,11 +17,11 @@ package net.sf.acegisecurity.adapters.cas; | |||||||
| 
 | 
 | ||||||
| import junit.framework.TestCase; | import junit.framework.TestCase; | ||||||
| 
 | 
 | ||||||
| import net.sf.acegisecurity.MockHttpServletRequest; |  | ||||||
| 
 |  | ||||||
| import org.springframework.context.ApplicationContext; | import org.springframework.context.ApplicationContext; | ||||||
| import org.springframework.context.support.ClassPathXmlApplicationContext; | import org.springframework.context.support.ClassPathXmlApplicationContext; | ||||||
| 
 | 
 | ||||||
|  | import org.springframework.mock.web.MockHttpServletRequest; | ||||||
|  | 
 | ||||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -70,7 +70,7 @@ public class CasPasswordHandlerProxyTests extends TestCase { | |||||||
|                 "net/sf/acegisecurity/adapters/cas/applicationContext-invalid.xml"); |                 "net/sf/acegisecurity/adapters/cas/applicationContext-invalid.xml"); | ||||||
| 
 | 
 | ||||||
|         try { |         try { | ||||||
|             proxy.authenticate(new MockHttpServletRequest("/"), "x", "y"); |             proxy.authenticate(new MockHttpServletRequest(), "x", "y"); | ||||||
|             fail("Should have thrown IllegalArgumentException"); |             fail("Should have thrown IllegalArgumentException"); | ||||||
|         } catch (IllegalArgumentException expected) { |         } catch (IllegalArgumentException expected) { | ||||||
|             assertEquals("Bean context must contain at least one bean of type CasPasswordHandler", |             assertEquals("Bean context must contain at least one bean of type CasPasswordHandler", | ||||||
| @ -81,11 +81,11 @@ public class CasPasswordHandlerProxyTests extends TestCase { | |||||||
|     public void testNormalOperation() { |     public void testNormalOperation() { | ||||||
|         CasPasswordHandlerProxy proxy = new MockCasPasswordHandlerProxy( |         CasPasswordHandlerProxy proxy = new MockCasPasswordHandlerProxy( | ||||||
|                 "net/sf/acegisecurity/adapters/cas/applicationContext-valid.xml"); |                 "net/sf/acegisecurity/adapters/cas/applicationContext-valid.xml"); | ||||||
|         assertTrue(proxy.authenticate(new MockHttpServletRequest("/"), |         assertTrue(proxy.authenticate(new MockHttpServletRequest(), "marissa", | ||||||
|                 "marissa", "koala")); |                 "koala")); | ||||||
|         assertFalse(proxy.authenticate(new MockHttpServletRequest("/"), |         assertFalse(proxy.authenticate(new MockHttpServletRequest(), "marissa", | ||||||
|                 "marissa", "WRONG_PASSWORD")); |                 "WRONG_PASSWORD")); | ||||||
|         assertFalse(proxy.authenticate(new MockHttpServletRequest("/"), |         assertFalse(proxy.authenticate(new MockHttpServletRequest(), | ||||||
|                 "INVALID_USER_NAME", "WRONG_PASSWORD")); |                 "INVALID_USER_NAME", "WRONG_PASSWORD")); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -18,7 +18,8 @@ package net.sf.acegisecurity.adapters.cas; | |||||||
| import junit.framework.TestCase; | import junit.framework.TestCase; | ||||||
| 
 | 
 | ||||||
| import net.sf.acegisecurity.MockAuthenticationManager; | import net.sf.acegisecurity.MockAuthenticationManager; | ||||||
| import net.sf.acegisecurity.MockHttpServletRequest; | 
 | ||||||
|  | import org.springframework.mock.web.MockHttpServletRequest; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| @ -54,7 +55,7 @@ public class CasPasswordHandlerTests extends TestCase { | |||||||
|         handler.setAuthenticationManager(new MockAuthenticationManager(false)); |         handler.setAuthenticationManager(new MockAuthenticationManager(false)); | ||||||
|         handler.afterPropertiesSet(); |         handler.afterPropertiesSet(); | ||||||
| 
 | 
 | ||||||
|         assertFalse(handler.authenticate(new MockHttpServletRequest("/"), |         assertFalse(handler.authenticate(new MockHttpServletRequest(), | ||||||
|                 "username", "password")); |                 "username", "password")); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -84,16 +85,15 @@ public class CasPasswordHandlerTests extends TestCase { | |||||||
|         handler.afterPropertiesSet(); |         handler.afterPropertiesSet(); | ||||||
| 
 | 
 | ||||||
|         // If empty or null username we return false |         // If empty or null username we return false | ||||||
|         assertFalse(handler.authenticate(new MockHttpServletRequest("/"), "", |         assertFalse(handler.authenticate(new MockHttpServletRequest(), "", | ||||||
|                 "password")); |                 "password")); | ||||||
|         assertFalse(handler.authenticate(new MockHttpServletRequest("/"), null, |         assertFalse(handler.authenticate(new MockHttpServletRequest(), null, | ||||||
|                 "password")); |                 "password")); | ||||||
| 
 | 
 | ||||||
|         // We authenticate with null passwords (they might not have one) |         // We authenticate with null passwords (they might not have one) | ||||||
|         assertTrue(handler.authenticate(new MockHttpServletRequest("/"), |         assertTrue(handler.authenticate(new MockHttpServletRequest(), "user", | ||||||
|                 "user", null)); |                 null)); | ||||||
|         assertTrue(handler.authenticate(new MockHttpServletRequest("/"), |         assertTrue(handler.authenticate(new MockHttpServletRequest(), "user", "")); | ||||||
|                 "user", "")); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void testNormalOperation() throws Exception { |     public void testNormalOperation() throws Exception { | ||||||
| @ -101,7 +101,7 @@ public class CasPasswordHandlerTests extends TestCase { | |||||||
|         handler.setAuthenticationManager(new MockAuthenticationManager(true)); |         handler.setAuthenticationManager(new MockAuthenticationManager(true)); | ||||||
|         handler.afterPropertiesSet(); |         handler.afterPropertiesSet(); | ||||||
| 
 | 
 | ||||||
|         assertTrue(handler.authenticate(new MockHttpServletRequest("/"), |         assertTrue(handler.authenticate(new MockHttpServletRequest(), | ||||||
|                 "username", "password")); |                 "username", "password")); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -19,10 +19,11 @@ import junit.framework.TestCase; | |||||||
| 
 | 
 | ||||||
| import net.sf.acegisecurity.GrantedAuthority; | import net.sf.acegisecurity.GrantedAuthority; | ||||||
| import net.sf.acegisecurity.GrantedAuthorityImpl; | import net.sf.acegisecurity.GrantedAuthorityImpl; | ||||||
| import net.sf.acegisecurity.MockHttpServletRequest; |  | ||||||
| import net.sf.acegisecurity.adapters.MockPrincipal; | import net.sf.acegisecurity.adapters.MockPrincipal; | ||||||
| import net.sf.acegisecurity.adapters.PrincipalAcegiUserToken; | import net.sf.acegisecurity.adapters.PrincipalAcegiUserToken; | ||||||
| 
 | 
 | ||||||
|  | import org.springframework.mock.web.MockHttpServletRequest; | ||||||
|  | 
 | ||||||
| import java.security.Principal; | import java.security.Principal; | ||||||
| 
 | 
 | ||||||
| import java.util.HashSet; | import java.util.HashSet; | ||||||
| @ -68,8 +69,7 @@ public class JbossIntegrationFilterTests extends TestCase { | |||||||
|         JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext( |         JbossIntegrationFilter filter = new MockJbossIntegrationFilter(new MockInitialContext( | ||||||
|                     makeIntoSubject(principal))); |                     makeIntoSubject(principal))); | ||||||
| 
 | 
 | ||||||
|         Object result = filter.extractFromContainer(new MockHttpServletRequest( |         Object result = filter.extractFromContainer(new MockHttpServletRequest()); | ||||||
|                     null, null)); |  | ||||||
| 
 | 
 | ||||||
|         if (!(result instanceof PrincipalAcegiUserToken)) { |         if (!(result instanceof PrincipalAcegiUserToken)) { | ||||||
|             fail("Should have returned PrincipalAcegiUserToken"); |             fail("Should have returned PrincipalAcegiUserToken"); | ||||||
| @ -78,8 +78,10 @@ public class JbossIntegrationFilterTests extends TestCase { | |||||||
|         PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result; |         PrincipalAcegiUserToken castResult = (PrincipalAcegiUserToken) result; | ||||||
|         assertEquals(principal, result); |         assertEquals(principal, result); | ||||||
| 
 | 
 | ||||||
|         filter.commitToContainer(new MockHttpServletRequest(principal, null), |         MockHttpServletRequest mockRequest = new MockHttpServletRequest(); | ||||||
|             principal); |         mockRequest.setUserPrincipal(principal); | ||||||
|  | 
 | ||||||
|  |         filter.commitToContainer(mockRequest, principal); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void testReturnsNullIfContextReturnsSomethingOtherThanASubject() { |     public void testReturnsNullIfContextReturnsSomethingOtherThanASubject() { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user