mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-10 04:13:31 +00:00
SEC-1430: Forgot to commit changes to new ExceptionMappingAuthenticationFailureHandlerTests.
This commit is contained in:
parent
2e98b84494
commit
183333d189
@ -1,11 +1,42 @@
|
|||||||
package org.springframework.security.web.authentication;
|
package org.springframework.security.web.authentication;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA.
|
* @author Luke Taylor
|
||||||
* User: luke
|
|
||||||
* Date: Aug 8, 2010
|
|
||||||
* Time: 5:13:18 PM
|
|
||||||
* To change this template use File | Settings | File Templates.
|
|
||||||
*/
|
*/
|
||||||
public class ExceptionMappingAuthenticationFailureHandlerTests {
|
public class ExceptionMappingAuthenticationFailureHandlerTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void defaultTargetUrlIsUsedIfNoMappingExists() throws Exception {
|
||||||
|
ExceptionMappingAuthenticationFailureHandler fh = new ExceptionMappingAuthenticationFailureHandler();
|
||||||
|
fh.setDefaultFailureUrl("/failed");
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
fh.onAuthenticationFailure(new MockHttpServletRequest(), response, new BadCredentialsException(""));
|
||||||
|
|
||||||
|
assertEquals("/failed", response.getRedirectedUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void exceptionMapIsUsedIfMappingExists() throws Exception {
|
||||||
|
ExceptionMappingAuthenticationFailureHandler fh = new ExceptionMappingAuthenticationFailureHandler();
|
||||||
|
HashMap<String, String> mapping = new HashMap<String, String>();
|
||||||
|
mapping.put("org.springframework.security.authentication.BadCredentialsException", "/badcreds");
|
||||||
|
fh.setExceptionMappings(mapping);
|
||||||
|
fh.setDefaultFailureUrl("/failed");
|
||||||
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
fh.onAuthenticationFailure(new MockHttpServletRequest(), response, new BadCredentialsException(""));
|
||||||
|
|
||||||
|
assertEquals("/badcreds", response.getRedirectedUrl());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user