org.springframework.web.filter.ForwardedHeaderFilter Java Examples

The following examples show how to use org.springframework.web.filter.ForwardedHeaderFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SecurityConfig.java    From teiid-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(HttpSecurity http) throws Exception {
    super.configure(http);
    http.addFilterBefore(new ForwardedHeaderFilter(), KeycloakPreAuthActionsFilter.class);
    http.authorizeRequests()
    .antMatchers("/static/**", "/actuator/health", "/odata/$metadata", "/odata/swagger.json",
            "/odata/openapi.json", "/odata/**/$metadata", "/odata/**/swagger.json", "/odata/**/openapi.json")
    .permitAll()
    .and()
    .authorizeRequests().anyRequest().authenticated();
}
 
Example #2
Source File: ManagementApiServer.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
public void attachHandlers() {

        // Create the servlet context
        final ServletContextHandler context = new ServletContextHandler(this.server, entrypoint, ServletContextHandler.SESSIONS);

        // REST configuration
        final ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
        servletHolder.setInitParameter("javax.ws.rs.Application", ManagementApplication.class.getName());
        servletHolder.setInitOrder(1);
        servletHolder.setAsyncSupported(true);

        AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
        webApplicationContext.setEnvironment((ConfigurableEnvironment) applicationContext.getEnvironment());
        webApplicationContext.setParent(applicationContext);
        webApplicationContext.setServletContext(context.getServletContext());

        webApplicationContext.register(ManagementConfiguration.class);

        context.addEventListener(new ContextLoaderListener(webApplicationContext));
        context.addServlet(servletHolder, "/*");
        context.addServlet(new ServletHolder(new DispatcherServlet(webApplicationContext)), "/auth/*");

        // X-Forwarded-* support
        context.addFilter(ForwardedHeaderFilter.class, "/*", EnumSet.allOf(DispatcherType.class));

        // Spring Security filter
        context.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")), "/*", EnumSet.allOf(DispatcherType.class));
    }
 
Example #3
Source File: LealoneServletWebServerFactoryAutoConfiguration.java    From Lealone-Plugins with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingFilterBean(ForwardedHeaderFilter.class)
@ConditionalOnProperty(value = "server.forward-headers-strategy", havingValue = "framework")
public FilterRegistrationBean<ForwardedHeaderFilter> forwardedHeaderFilter() {
    ForwardedHeaderFilter filter = new ForwardedHeaderFilter();
    FilterRegistrationBean<ForwardedHeaderFilter> registration = new FilterRegistrationBean<>(filter);
    registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC, DispatcherType.ERROR);
    registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
    return registration;
}
 
Example #4
Source File: FairControllerTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@BeforeEach
void beforeTest() {
  dataService = mock(DataService.class);
  entityModelWriter = mock(EntityModelWriter.class);
  FairController controller = new FairController(dataService, entityModelWriter);

  mockMvc =
      MockMvcBuilders.standaloneSetup(controller)
          .setMessageConverters(
              new FormHttpMessageConverter(), gsonHttpMessageConverter, new RdfConverter())
          .addFilter(new ForwardedHeaderFilter())
          .build();
}
 
Example #5
Source File: WebAppSecurityInitializer.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
  // add filters
  Dynamic forwardedHeaderFilter =
      servletContext.addFilter("forwardedHeaderFilter", ForwardedHeaderFilter.class);
  forwardedHeaderFilter.setAsyncSupported(true);
  forwardedHeaderFilter.addMappingForUrlPatterns(EnumSet.of(REQUEST, ERROR, ASYNC), false, "*");
}
 
Example #6
Source File: MvcUriComponentsBuilderTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
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));
}
 
Example #7
Source File: ServletUriComponentsBuilderTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private HttpServletRequest adaptFromForwardedHeaders(HttpServletRequest request) throws Exception {
	MockFilterChain chain = new MockFilterChain();
	new ForwardedHeaderFilter().doFilter(request, new MockHttpServletResponse(), chain);
	return (HttpServletRequest) chain.getRequest();
}
 
Example #8
Source File: WebUtilsTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private HttpServletRequest adaptFromForwardedHeaders(HttpServletRequest request) throws Exception {
	MockFilterChain chain = new MockFilterChain();
	new ForwardedHeaderFilter().doFilter(request, new MockHttpServletResponse(), chain);
	return (HttpServletRequest) chain.getRequest();
}
 
Example #9
Source File: MvcUriComponentsBuilderTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
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));
}
 
Example #10
Source File: ServletUriComponentsBuilderTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private HttpServletRequest adaptFromForwardedHeaders(HttpServletRequest request) throws Exception {
	MockFilterChain chain = new MockFilterChain();
	new ForwardedHeaderFilter().doFilter(request, new MockHttpServletResponse(), chain);
	return (HttpServletRequest) chain.getRequest();
}
 
Example #11
Source File: WebUtilsTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private HttpServletRequest adaptFromForwardedHeaders(HttpServletRequest request) throws Exception {
	MockFilterChain chain = new MockFilterChain();
	new ForwardedHeaderFilter().doFilter(request, new MockHttpServletResponse(), chain);
	return (HttpServletRequest) chain.getRequest();
}
 
Example #12
Source File: BaseApplicationConfig.java    From spring-boot-doma2-sample with Apache License 2.0 4 votes vote down vote up
@Bean
public ForwardedHeaderFilter forwardedHeaderFilter() {
    // X-Forwarded-XXXの値を使ってリクエスト情報を上書きする
    return new ForwardedHeaderFilter();
}
 
Example #13
Source File: DataFlowServerConfiguration.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
public Filter forwardedHeaderFilter() {
	return new ForwardedHeaderFilter();
}