|
|
|
@ -94,8 +94,9 @@ public class ExceptionTranslationFilterTests { |
|
|
|
|
|
|
|
|
|
|
|
// Test
|
|
|
|
// Test
|
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint()); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint); |
|
|
|
filter.setAuthenticationTrustResolver(new AuthenticationTrustResolverImpl()); |
|
|
|
filter.setAuthenticationTrustResolver(new AuthenticationTrustResolverImpl()); |
|
|
|
|
|
|
|
assertNotNull(filter.getAuthenticationTrustResolver()); |
|
|
|
|
|
|
|
|
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
filter.doFilter(request, response, fc); |
|
|
|
filter.doFilter(request, response, fc); |
|
|
|
@ -123,7 +124,7 @@ public class ExceptionTranslationFilterTests { |
|
|
|
|
|
|
|
|
|
|
|
// Test
|
|
|
|
// Test
|
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint()); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint); |
|
|
|
filter.setAccessDeniedHandler(adh); |
|
|
|
filter.setAccessDeniedHandler(adh); |
|
|
|
|
|
|
|
|
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
@ -149,7 +150,7 @@ public class ExceptionTranslationFilterTests { |
|
|
|
|
|
|
|
|
|
|
|
// Test
|
|
|
|
// Test
|
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint()); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint); |
|
|
|
filter.afterPropertiesSet(); |
|
|
|
filter.afterPropertiesSet(); |
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
filter.doFilter(request, response, fc); |
|
|
|
filter.doFilter(request, response, fc); |
|
|
|
@ -175,7 +176,7 @@ public class ExceptionTranslationFilterTests { |
|
|
|
|
|
|
|
|
|
|
|
// Test
|
|
|
|
// Test
|
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint()); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint); |
|
|
|
HttpSessionRequestCache requestCache = new HttpSessionRequestCache(); |
|
|
|
HttpSessionRequestCache requestCache = new HttpSessionRequestCache(); |
|
|
|
requestCache.setPortResolver(new MockPortResolver(8080, 8443)); |
|
|
|
requestCache.setPortResolver(new MockPortResolver(8080, 8443)); |
|
|
|
filter.setRequestCache(requestCache); |
|
|
|
filter.setRequestCache(requestCache); |
|
|
|
@ -197,7 +198,7 @@ public class ExceptionTranslationFilterTests { |
|
|
|
@Test(expected=IllegalArgumentException.class) |
|
|
|
@Test(expected=IllegalArgumentException.class) |
|
|
|
public void startupDetectsMissingRequestCache() throws Exception { |
|
|
|
public void startupDetectsMissingRequestCache() throws Exception { |
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint()); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint); |
|
|
|
|
|
|
|
|
|
|
|
filter.setRequestCache(null); |
|
|
|
filter.setRequestCache(null); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -210,7 +211,8 @@ public class ExceptionTranslationFilterTests { |
|
|
|
|
|
|
|
|
|
|
|
// Test
|
|
|
|
// Test
|
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint()); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint); |
|
|
|
|
|
|
|
assertSame(mockEntryPoint, filter.getAuthenticationEntryPoint()); |
|
|
|
|
|
|
|
|
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
MockHttpServletResponse response = new MockHttpServletResponse(); |
|
|
|
filter.doFilter(request, response, mock(FilterChain.class)); |
|
|
|
filter.doFilter(request, response, mock(FilterChain.class)); |
|
|
|
@ -220,7 +222,7 @@ public class ExceptionTranslationFilterTests { |
|
|
|
public void thrownIOExceptionServletExceptionAndRuntimeExceptionsAreRethrown() throws Exception { |
|
|
|
public void thrownIOExceptionServletExceptionAndRuntimeExceptionsAreRethrown() throws Exception { |
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
ExceptionTranslationFilter filter = new ExceptionTranslationFilter(); |
|
|
|
|
|
|
|
|
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint()); |
|
|
|
filter.setAuthenticationEntryPoint(mockEntryPoint); |
|
|
|
filter.afterPropertiesSet(); |
|
|
|
filter.afterPropertiesSet(); |
|
|
|
Exception[] exceptions = {new IOException(), new ServletException(), new RuntimeException()}; |
|
|
|
Exception[] exceptions = {new IOException(), new ServletException(), new RuntimeException()}; |
|
|
|
for (Exception e : exceptions) { |
|
|
|
for (Exception e : exceptions) { |
|
|
|
@ -237,12 +239,10 @@ public class ExceptionTranslationFilterTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private AuthenticationEntryPoint mockEntryPoint() { |
|
|
|
private final AuthenticationEntryPoint mockEntryPoint = new AuthenticationEntryPoint() { |
|
|
|
return new AuthenticationEntryPoint() { |
|
|
|
public void commence(HttpServletRequest request, HttpServletResponse response, |
|
|
|
public void commence(HttpServletRequest request, HttpServletResponse response, |
|
|
|
|
|
|
|
AuthenticationException authException) throws IOException, ServletException { |
|
|
|
AuthenticationException authException) throws IOException, ServletException { |
|
|
|
response.sendRedirect(request.getContextPath() + "/login.jsp"); |
|
|
|
response.sendRedirect(request.getContextPath() + "/login.jsp"); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|