I use Spring Boot 2.5.6. I want to skip specific URL (/doc.html
).
I have created a JwtAuthenticationTokenFilter
extending OncePerRequestFilter
@Component
public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
//the logic of authentication
}
And then I create SecurityConfig
extending WebSecurityConfigurerAdapter
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
@Order(1)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web)
throws Exception {
web.ignoring()
.antMatchers(HttpMethod.OPTIONS, "/**")
.antMatchers("/doc.html");
}
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.csrf().disable()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()
.antMatchers("/doc.html").anonymous()
.and()
.requestMatchers().antMatchers("/doc.html");
but when I access localhost:8080/doc.html
, the /doc.html
didn't skip;
and I also try to override shouldNotFilter
in JwtAuthenticationTokenFilter.java
, but it did't work also:
@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
return (
new AntPathMatcher().match("/doc.html", request.getServletPath()));
}