Search in sources :

Example 1 with ForwardedHeaderFilter

use of org.springframework.web.filter.ForwardedHeaderFilter in project spring-framework by spring-projects.

the class WebUtilsTests method adaptFromForwardedHeaders.

// SPR-16668
private HttpServletRequest adaptFromForwardedHeaders(HttpServletRequest request) throws Exception {
    MockFilterChain chain = new MockFilterChain();
    new ForwardedHeaderFilter().doFilter(request, new MockHttpServletResponse(), chain);
    return (HttpServletRequest) chain.getRequest();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ForwardedHeaderFilter(org.springframework.web.filter.ForwardedHeaderFilter) MockFilterChain(org.springframework.web.testfixture.servlet.MockFilterChain) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse)

Example 2 with ForwardedHeaderFilter

use of org.springframework.web.filter.ForwardedHeaderFilter in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method adaptRequestFromForwardedHeaders.

// SPR-16668
private void adaptRequestFromForwardedHeaders() throws Exception {
    MockFilterChain chain = new MockFilterChain();
    new ForwardedHeaderFilter().doFilter(this.request, new MockHttpServletResponse(), chain);
    HttpServletRequest adaptedRequest = (HttpServletRequest) chain.getRequest();
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(adaptedRequest));
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ForwardedHeaderFilter(org.springframework.web.filter.ForwardedHeaderFilter) MockFilterChain(org.springframework.web.testfixture.servlet.MockFilterChain) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse)

Example 3 with ForwardedHeaderFilter

use of org.springframework.web.filter.ForwardedHeaderFilter in project snow-owl by b2ihealthcare.

the class SnowOwlSecurityConfig method configure.

@SuppressWarnings({ "lgtm[java/spring-disabled-csrf-protection]" })
@Override
protected void configure(final HttpSecurity http) throws Exception {
    http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().csrf().disable();
    // handle X-Forwarded headers
    http.addFilterBefore(new ForwardedHeaderFilter(), BasicAuthenticationFilter.class);
    // add dev time CORS filter
    if (PlatformUtil.isDevVersion()) {
        http.addFilterAfter(new CORSFilter(), BasicAuthenticationFilter.class);
    }
    // authentication is handled internally in AuthorizedRequest
    http.authorizeRequests().antMatchers("/**").permitAll();
}
Also used : ForwardedHeaderFilter(org.springframework.web.filter.ForwardedHeaderFilter) CORSFilter(com.b2international.snowowl.core.rest.util.CORSFilter)

Example 4 with ForwardedHeaderFilter

use of org.springframework.web.filter.ForwardedHeaderFilter in project spring-framework by spring-projects.

the class ServletUriComponentsBuilderTests method adaptFromForwardedHeaders.

// SPR-16668
private HttpServletRequest adaptFromForwardedHeaders(HttpServletRequest request) throws Exception {
    MockFilterChain chain = new MockFilterChain();
    new ForwardedHeaderFilter().doFilter(request, new MockHttpServletResponse(), chain);
    return (HttpServletRequest) chain.getRequest();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ForwardedHeaderFilter(org.springframework.web.filter.ForwardedHeaderFilter) MockFilterChain(org.springframework.web.testfixture.servlet.MockFilterChain) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse)

Aggregations

ForwardedHeaderFilter (org.springframework.web.filter.ForwardedHeaderFilter)4 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)3 MockFilterChain (org.springframework.web.testfixture.servlet.MockFilterChain)3 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)3 CORSFilter (com.b2international.snowowl.core.rest.util.CORSFilter)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1