Reputation: 7647
I have a authentication filter which extends spring security, AbstractAuthenticationProcessingFilter . So in this case I can set the request matcher as below,
MyAuthenticationFilter authFilter = new MyAuthenticationFilter();
authFilter.setRequiresAuthenticationRequestMatcher(new AntPathRequestMatcher("/api/**"));
I create another filter does not necessary to have a authentication functionality. So I extend it using GenericFilterBean. In this case how I can add AntPathRequestMatcher as above?
Upvotes: 2
Views: 9830
Reputation: 120781
You need to invoke RequestMatcher.matches(HttpServletRequest request)
RequestMatcher myMatcher = AntPathRequestMatcher("/api/**");
...
@Override
void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) {
if (myMatcher.matches(request)) {
...
} else {
...
}
chain.doFilter(request, response);
}
Upvotes: 5