I want to secure only few specific endpoints and if any request comes to secured endpoint I want to apply filter on that.
This is what I have tried as of now:
http
.csrf().disable()
.addFilterAfter((Filter) MyFilter, UsernamePasswordAuthenticationFilter.class)
.authorizeRequests()
.antMatchers("/api/users").permitAll()
.anyRequest().authenticated();
I am expecting that it should secure only /api/users
and if any request comes to this secured endpoint, then it should go through the filter. But right now each request is going through the filter.
Please suggest what is the right way to do this.