title: Authenticate only selected rest end points : spring boot
body: <p>I have a Spring Boot web application exposing few rest endpoints. I wanted to know how we can enable basic authentication only for selected rest endpoints. Let's say I want only <code>/employee/{id}</code> request to be authenticated and ignore all the other rest endpoints. I am using the following code. My question is will the <code>antMatcher</code> only authenticate the request specified? Currently its enabling authentication for all rest endpoints: </p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
      @Override
      protected void configure(HttpSecurity http) throws Exception {
           // How does it work will it only authenticate employee &amp; 
           // ignore any other request?? Its authenticating all the requests currently. 
           http
              .authorizeRequests()
                   .antMatchers("/employee/*").authenticated()
              .and()
              .httpBasic()
              .and()
              .csrf()
                  .disable();    
      }
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          auth
              .inMemoryAuthentication()
                  .withUser("admin").password("admin").roles("USER");
      }
  }
  </code></pre>