title: What is the difference between hasRole() and hasAuthority() in Spring Security
body: <p>assume that I have an user who has following authentication:</p>
  
  <pre><code> List&lt;GrantedAuthority&gt; grantedAuthorities = new ArrayList&lt;&gt;();
   grantedAuthorities.add(new SimpleGrantedAuthority("READ_PRODUCT"));
   grantedAuthorities.add(new SimpleGrantedAuthority("WRITE_PRODUCT"));
  
   SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("usr", "pwd", grantedAuthorities));
  </code></pre>
  
  <p>In the security check, I should check if the user has the right authority to access the API. I did the following to achive it:</p>
  
  <pre><code> http
      .httpBasic().disable()
      .authorizeRequests()
      .antMatchers(HttpMethod.GET, "/product/**").hasAuthority("READ_PRODUCT");
  </code></pre>
  
  <p>Here I use <code>hasAuthority()</code> to check if the user has the right authority, but I found that there is also a method called <code>hasRole()</code> but I dont know that is the difference between these two methods? Can anyone explain me the difference and if I want to use <code>hasRole()</code> here, how can I use it here? I tried to replace <code>hasAuthority()</code> by <code>hasRole()</code> but it was not successful</p>