title: Unauthorized restTemplate exchange with role secured endpoint
body: <p>I am trying to add spring security to my rest api and secure one of endpoints.
  I added UserEntity which implements UserDetails and RoleEntity to Rest Api. They exists in database, and user has roles:</p>
  <pre><code>public class UserEntity implements UserDetails {
  @Id
  @GeneratedValue(generator = &quot;system-uuid&quot;)
  @GenericGenerator(name = &quot;system-uuid&quot;, strategy = &quot;uuid&quot;)
  @Column(name=&quot;id&quot;)
  private String id;
  private String name;
  private String password;
  @ManyToMany
  @JoinTable(
          name = &quot;user_roles&quot;,
          joinColumns = @JoinColumn(name = &quot;user_id&quot;),
          inverseJoinColumns = @JoinColumn(name = &quot;role_id&quot;))
  private Set&lt;RoleEntity&gt; roles;
  </code></pre>
  <p>and overrided necessary methods from UserDetails and set up them on true.</p>
  <pre><code>@Override
  public Collection&lt;? extends GrantedAuthority&gt; getAuthorities() {
      List&lt;SimpleGrantedAuthority&gt; authorities = new ArrayList&lt;&gt;();
      for (RoleEntity role : getRoles()) {
          authorities.add(new SimpleGrantedAuthority(role.getName()));
      }
      return authorities;
  }
  
  @Override
  public String getUsername() {
      return name;
  }
  
  @Override
  public String getPassword() {
      return password;
  }
  </code></pre>
  <p>In MyWebSecurityConfig which extends WebSecurityConfigurerAdapter added configuration:</p>
  <pre><code> @Override
  protected void configure(HttpSecurity http) throws Exception {
      http
              .authorizeRequests()
              .antMatchers(&quot;/offences&quot;, &quot;/offences/*&quot;, &quot;/offences/**&quot;).hasRole(&quot;ADMIN&quot;)
              .anyRequest().permitAll()
              .and()
              .httpBasic();
  }
  </code></pre>
  <p>and It is working too. Endpoint is secured. But when I hardcoded some user (with &quot;admin&quot; username and password) in other app to send request:</p>
  <pre><code>public HashMap&lt;Boolean, Object&gt; find(FindOffenceForm findOffenceForm) {
    
      HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.setBasicAuth(&quot;admin&quot;, &quot;admin&quot;);
  
      HttpEntity&lt;String&gt; request = new HttpEntity&lt;&gt;(httpHeaders);
      try {
          ResponseEntity&lt;String&gt; responseEntity = restTemplate.exchange(URL_OFFENCE + &quot;/find/&quot; + findOffenceForm.getName(),
                  HttpMethod.GET, request, String.class);
          result.put(true, objectMapper.readValue(responseEntity.getBody(), new TypeReference&lt;Set&lt;OffenceDTO&gt;&gt;() {
          }));
      } catch (Exception ex) {
          result.put(false, ex.getMessage());
      }
  </code></pre>
  <p><em>I am getting 401 Unauthorized and in my api I can see message
  WARN 13660 o.s.s.c.bcrypt.BCryptPasswordEncoder : Encoded password does not look like BCrypt.
  While sending request in resttemaplete, should I code password for bcrypt?</em></p>
  <p><strong>EDIT: OK, so in my database I have not code password for bcrypt. I changed it and now I am getting 403 Forbidden.
  I added to config .csrf().and().cors().disabled but nothing changed.</strong></p>