use of jakarta.servlet.FilterChain in project spring-security by spring-projects.
the class SwitchUserFilterTests method redirectToTargetUrlIsCorrect.
@Test
public void redirectToTargetUrlIsCorrect() throws Exception {
MockHttpServletRequest request = createMockSwitchRequest();
request.setContextPath("/webapp");
request.addParameter(SwitchUserFilter.SPRING_SECURITY_SWITCH_USERNAME_KEY, "jacklord");
request.setRequestURI("/webapp/login/impersonate");
SwitchUserFilter filter = new SwitchUserFilter();
filter.setSwitchUserUrl("/login/impersonate");
filter.setSuccessHandler(new SimpleUrlAuthenticationSuccessHandler("/someOtherUrl"));
filter.setUserDetailsService(new MockUserDetailsService());
FilterChain chain = mock(FilterChain.class);
MockHttpServletResponse response = new MockHttpServletResponse();
filter.doFilter(request, response, chain);
verify(chain, never()).doFilter(request, response);
assertThat(response.getRedirectedUrl()).isEqualTo("/webapp/someOtherUrl");
}
use of jakarta.servlet.FilterChain in project spring-security by spring-projects.
the class ConcurrentSessionFilterTests method returnsExpectedMessageWhenNoExpiredUrlSet.
// As above, but with no expiredUrl set.
@Test
public void returnsExpectedMessageWhenNoExpiredUrlSet() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpSession session = new MockHttpSession();
request.setSession(session);
MockHttpServletResponse response = new MockHttpServletResponse();
SessionRegistry registry = new SessionRegistryImpl();
registry.registerNewSession(session.getId(), "principal");
registry.getSessionInformation(session.getId()).expireNow();
ConcurrentSessionFilter filter = new ConcurrentSessionFilter(registry);
FilterChain fc = mock(FilterChain.class);
filter.doFilter(request, response, fc);
verifyZeroInteractions(fc);
assertThat(response.getContentAsString()).isEqualTo("This session has been expired (possibly due to multiple concurrent logins being " + "attempted as the same user).");
}
use of jakarta.servlet.FilterChain in project tomcat by apache.
the class Request method getNonAsyncClassNames.
private Set<String> getNonAsyncClassNames() {
Set<String> result = new HashSet<>();
Wrapper wrapper = getWrapper();
if (!wrapper.isAsyncSupported()) {
result.add(wrapper.getServletClass());
}
FilterChain filterChain = getFilterChain();
if (filterChain instanceof ApplicationFilterChain) {
((ApplicationFilterChain) filterChain).findNonAsyncFilters(result);
} else {
result.add(sm.getString("coyoteRequest.filterAsyncSupportUnknown"));
}
Container c = wrapper;
while (c != null) {
c.getPipeline().findNonAsyncValves(result);
c = c.getParent();
}
return result;
}
use of jakarta.servlet.FilterChain in project spring-framework by spring-projects.
the class ServletInvocableHandlerMethodTests method invokeAndHandle_VoidNotModifiedWithEtag.
@Test
public void invokeAndHandle_VoidNotModifiedWithEtag() throws Exception {
String eTagValue = "\"deadb33f8badf00d\"";
FilterChain chain = (req, res) -> {
request.addHeader(HttpHeaders.IF_NONE_MATCH, eTagValue);
webRequest.checkNotModified(eTagValue);
try {
ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new Handler(), "notModified");
handlerMethod.invokeAndHandle(webRequest, mavContainer);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
};
new ShallowEtagHeaderFilter().doFilter(this.request, this.response, chain);
assertThat(response.getStatus()).isEqualTo(304);
assertThat(response.getHeader(HttpHeaders.ETAG)).isEqualTo(eTagValue);
assertThat(response.getContentAsString()).isEmpty();
}
use of jakarta.servlet.FilterChain in project spring-framework by spring-projects.
the class ResourceUrlEncodingFilterTests method testEncodeUrl.
private void testEncodeUrl(MockHttpServletRequest request, String url, String expected) throws ServletException, IOException {
FilterChain chain = (req, res) -> {
req.setAttribute(ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR, this.urlProvider);
String result = ((HttpServletResponse) res).encodeURL(url);
assertThat(result).isEqualTo(expected);
};
this.filter.doFilter(request, new MockHttpServletResponse(), chain);
}
Aggregations