I am using Spring-Security 3.2.4 and Spring Boot 1.1.0 (and related 4.X dependency versions). I am writing a web application that will run in the built-in tomcat.
I am trying to add two additional filters (not related to Spring security) that one of them will be called before Spring -Security-FilterChainProxy, and the other will be called after Spring - Security-FilterChainProxy.
My Spring-Security configuration files:
@Configuration @EnableWebMvcSecurity public class SecurityCtxConfig extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser("user").password("pass").roles("USER"); } @Override protected void configure(HttpSecurity http) throws Exception { http.csrf() .disable() .authorizeRequests() .anyRequest() .authenticated() .and() .formLogin() .usernameParameter("user").passwordParameter("password"); } }
And the main class (Application.class):
@Configuration @ComponentScan @EnableAutoConfiguration public class Application { @Bean RequestFilter beforeSpringSecurityFilter(){ return new RequestFilter(); } @Bean RequestFilter afterSpringSecurityFilter(){ return new RequestFilter(); } public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
And filter implementation:
public class RequestFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { filterChain.doFilter(request, response); } }
Is there a way to control the order of the call when accounting for FilterChainProxy (which is created by the WebSecurityConfigurerAdapter? To be sure, the required order is:
- request-filter-1
- Spring-Security FilterChain
- query filter 2
thanks
source share