use of org.springframework.mock.web.MockFilterChain in project spring-framework by spring-projects.
the class ConditionalDelegatingFilterProxyTests method assertFilterNotInvoked.
private void assertFilterNotInvoked(String requestUri, String pattern) throws Exception {
request.setRequestURI(request.getContextPath() + requestUri);
filter = new PatternMappingFilterProxy(delegate, pattern);
filter.doFilter(request, response, filterChain);
assertThat(delegate.request, equalTo((ServletRequest) null));
assertThat(delegate.response, equalTo((ServletResponse) null));
assertThat(delegate.chain, equalTo((FilterChain) null));
assertThat(filterChain.getRequest(), equalTo((ServletRequest) request));
assertThat(filterChain.getResponse(), equalTo((ServletResponse) response));
filterChain = new MockFilterChain();
}
use of org.springframework.mock.web.MockFilterChain in project spring-security by spring-projects.
the class ConcurrentSessionFilterTests method doFilterWhenOverrideThenCustomRedirectStrategyUsed.
@Test
public void doFilterWhenOverrideThenCustomRedirectStrategyUsed() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpSession session = new MockHttpSession();
request.setSession(session);
MockHttpServletResponse response = new MockHttpServletResponse();
RedirectStrategy redirect = mock(RedirectStrategy.class);
SessionRegistry registry = mock(SessionRegistry.class);
SessionInformation information = new SessionInformation("user", "sessionId", new Date(System.currentTimeMillis() - 1000));
information.expireNow();
when(registry.getSessionInformation(anyString())).thenReturn(information);
final String expiredUrl = "/expired";
ConcurrentSessionFilter filter = new ConcurrentSessionFilter(registry, expiredUrl + "will-be-overrridden") {
/* (non-Javadoc)
* @see org.springframework.security.web.session.ConcurrentSessionFilter#determineExpiredUrl(javax.servlet.http.HttpServletRequest, org.springframework.security.core.session.SessionInformation)
*/
@Override
protected String determineExpiredUrl(HttpServletRequest request, SessionInformation info) {
return expiredUrl;
}
};
filter.setRedirectStrategy(redirect);
filter.doFilter(request, response, new MockFilterChain());
verify(redirect).sendRedirect(request, response, expiredUrl);
}
use of org.springframework.mock.web.MockFilterChain in project spring-security by spring-projects.
the class ConcurrentSessionFilterTests method doFilterWhenCustomRedirectStrategyThenCustomRedirectStrategyUsed.
@Test
public void doFilterWhenCustomRedirectStrategyThenCustomRedirectStrategyUsed() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpSession session = new MockHttpSession();
request.setSession(session);
MockHttpServletResponse response = new MockHttpServletResponse();
RedirectStrategy redirect = mock(RedirectStrategy.class);
SessionRegistry registry = mock(SessionRegistry.class);
SessionInformation information = new SessionInformation("user", "sessionId", new Date(System.currentTimeMillis() - 1000));
information.expireNow();
when(registry.getSessionInformation(anyString())).thenReturn(information);
String expiredUrl = "/expired";
ConcurrentSessionFilter filter = new ConcurrentSessionFilter(registry, expiredUrl);
filter.setRedirectStrategy(redirect);
filter.doFilter(request, response, new MockFilterChain());
verify(redirect).sendRedirect(request, response, expiredUrl);
}
use of org.springframework.mock.web.MockFilterChain in project spring-security by spring-projects.
the class ConcurrentSessionFilterTests method doFilterWhenCustomLogoutHandlersThenHandlersUsed.
@Test
public void doFilterWhenCustomLogoutHandlersThenHandlersUsed() throws Exception {
LogoutHandler handler = mock(LogoutHandler.class);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpSession session = new MockHttpSession();
request.setSession(session);
MockHttpServletResponse response = new MockHttpServletResponse();
SessionRegistry registry = mock(SessionRegistry.class);
SessionInformation information = new SessionInformation("user", "sessionId", new Date(System.currentTimeMillis() - 1000));
information.expireNow();
when(registry.getSessionInformation(anyString())).thenReturn(information);
ConcurrentSessionFilter filter = new ConcurrentSessionFilter(registry);
filter.setLogoutHandlers(new LogoutHandler[] { handler });
filter.doFilter(request, response, new MockFilterChain());
verify(handler).logout(eq(request), eq(response), any(Authentication.class));
}
use of org.springframework.mock.web.MockFilterChain in project spring-security by spring-projects.
the class ConcurrentSessionFilterTests method doFilterWhenNoSessionThenChainIsContinued.
@Test
public void doFilterWhenNoSessionThenChainIsContinued() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RedirectStrategy redirect = mock(RedirectStrategy.class);
SessionRegistry registry = mock(SessionRegistry.class);
SessionInformation information = new SessionInformation("user", "sessionId", new Date(System.currentTimeMillis() - 1000));
information.expireNow();
when(registry.getSessionInformation(anyString())).thenReturn(information);
String expiredUrl = "/expired";
ConcurrentSessionFilter filter = new ConcurrentSessionFilter(registry, expiredUrl);
filter.setRedirectStrategy(redirect);
MockFilterChain chain = new MockFilterChain();
filter.doFilter(request, response, chain);
assertThat(chain.getRequest()).isNotNull();
}
Aggregations