title: using HttpSecurity.requestMatchers in class ResourceServerConfiguration.configure in spring oauth2
body: <p>I have been struggling to understand how and when to use <code>HttpSecurity.requestMatchers</code>. Though I use <code>HttpSecurity.requestMatchers</code> but I have call <code>authorizeRequests</code> and <code>antMatchers</code> to specify the security rules.</p>
  
  <p>When should I use </p>
  
  <pre><code> http.requestMatchers()
                .antMatchers("/secure/**","/patients/**","/patient/**", "/hello/**")
                .and()
                .authorizeRequests().antMatchers("/secure/**","/books/**","/book/**", "/hello/**")
                .hasAnyRole("ADMIN","USER");
  </code></pre>
  
  <p>over</p>
  
  <pre><code>      http
        .authorizeRequests().antMatchers("/secure/**","/books/**","/hello/**", "/hello/**")
        .hasAnyRole("ADMIN","USER");
  </code></pre>
  
  <p>A scenario would help me to understand the use-case of <code>HttpSecurity.requestMatchers</code> </p>
  
  <p>I did look into <a href="https://docs.spring.io/spring-security/site/docs/4.2.4.RELEASE/apidocs/org/springframework/security/config/annotation/web/builders/HttpSecurity.html#requestMatchers--" rel="noreferrer">requestMatchers</a>, but still not clear to me</p>