Spring Boot OAuth2 with custom security filter
<p>I have a spring boot setup with an OAuth2 authorization and resource server. The user is able to acquire tokens by making a POST request to <code>/oauth/token</code>. So far, so good.</p>

<p>However, I don't want to protect <code>/oauth/token</code> via BASIC auth but by means of a custom security filter.</p>

<p>I tried the following but <code>DemoAuthenticationFilter</code> is never called:</p>

<pre><code>@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
    // ...
    @Override
    public void configure(HttpSecurity http) throws Exception {
        // ...
        http.addFilterBefore(new DemoAuthenticationFilter(), BasicAuthenticationFilter.class);
        http.authorizeRequests().antMatchers("/oauth/token").authenticated();
    }
}
</code></pre>

<p>Also, if I try to add it to <code>WebSecurityConfigurerAdapter</code> the filter is only called <i>after</i> the request is authenticated via OAuth2:</p>

<pre><code>@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    // ...
    @Override
    protected void configure(HttpSecurity http) throws Exception {
       // ...
       http.addFilterBefore(new DemoAuthenticationFilter(), BasicAuthenticationFilter.class);
       http.authorizeRequests().antMatchers("/oauth/token").authenticated();
    }
}
</code></pre>

<p>Some simple example how to achieve this would be really helpful. Thank you!</p>