List of usage examples for org.springframework.mock.web MockFilterConfig MockFilterConfig
public MockFilterConfig(@Nullable ServletContext servletContext, String filterName)
From source file:org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilterTests.java
/** * SEC-571/* w w w .ja va2 s .co m*/ */ @Test public void testNoSessionIsCreatedIfAllowSessionCreationIsFalse() throws Exception { MockHttpServletRequest request = createMockAuthenticationRequest(); MockFilterConfig config = new MockFilterConfig(null, null); MockFilterChain chain = new MockFilterChain(true); MockHttpServletResponse response = new MockHttpServletResponse(); // Reject authentication, so exception would normally be stored in session MockAuthenticationFilter filter = new MockAuthenticationFilter(false); failureHandler.setAllowSessionCreation(false); filter.setAuthenticationFailureHandler(failureHandler); filter.doFilter(request, response, chain); assertThat(request.getSession(false)).isNull(); }
From source file:org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilterTests.java
/** * SEC-462/* w w w.j a v a2 s. co m*/ */ @Test public void testLoginErrorWithNoFailureUrlSendsUnauthorizedStatus() throws Exception { MockHttpServletRequest request = createMockAuthenticationRequest(); MockFilterConfig config = new MockFilterConfig(null, null); MockFilterChain chain = new MockFilterChain(true); MockHttpServletResponse response = new MockHttpServletResponse(); MockAuthenticationFilter filter = new MockAuthenticationFilter(false); successHandler.setDefaultTargetUrl("https://monkeymachine.co.uk/"); filter.setAuthenticationSuccessHandler(successHandler); filter.doFilter(request, response, chain); assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_UNAUTHORIZED); }