Spring REST Security : Enable Basic Authentication only on a specific endpoint
<p>I have configured Spring Security for my REST API (with HeaderHttpSessionStrategy).</p>

<p>My 'WebSecurityConfigurerAdapter' implementation looks as below.</p>

<pre><code>@Override
    protected void configure(HttpSecurity http) throws Exception {

        http

            .csrf().disable()

            .authorizeRequests()
                .antMatchers("/user/**").authenticated()
                .antMatchers("/**").permitAll()

                .and()
            .requestCache()
                .requestCache(new NullRequestCache())
                .and()

            .httpBasic()
            ;

    }
</code></pre>

<p>Now, how can I configure 'HttpSecurity' object so that the basic authentication is only possible with a specific endpoint.</p>

<p>For example: </p>

<p><strong>/user/login</strong> : Basic Authentication should only be possible on this end point.After sucessfull authentication x-auth-token header is returned.</p>

<p><strong>/user/create</strong> : Client should not be able to authenticate on this endpoint.Should only return 401.Can only be accessed using the 'x-auth-token' created using /user/login endpoint.</p>