How to apply Spring Security filter only on secured endpoints?
<p>I have the following Spring Security configuration:</p>
<pre class="lang-java prettyprint-override"><code>httpSecurity
        .csrf().disable()
        .exceptionHandling()
            .authenticationEntryPoint(unauthorizedHandler)
            .and()
        .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
            .and()
        .authorizeRequests()
            .antMatchers(&quot;/api/**&quot;).fullyAuthenticated()
            .and()
        .addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);
</code></pre>
<p>The <code>authenticationTokenFilterBean()</code> is applied even on endpoints that do not match <code>/api/**</code> expression. I also tried adding the following configuration code:</p>
<pre><code>@Override
public void configure(WebSecurity webSecurity) {
    webSecurity.ignoring().antMatchers(&quot;/some_endpoint&quot;);
}
</code></pre>
<p>but this still did not solve my problem. How can I tell Spring Security to apply filters only on endpoints that match the secured URI expression?</p>