title: RestTemplate authentication while setting userName and password
body: <p>I have a curl command but I want to pass this information with userName and password while calling the rest API, every thing I have tried doesn't work. </p>
  
  <pre><code>curl -u E-BOARD:HVRid992Xl740NnWOkjk -X GET --header 'Accept: application/json' 'https://XXXXXX.fr/AAAAAA/BBBBB/v1/details?abc=hsdfh&amp;zyx=asdfsdf
  </code></pre>
  
  <p>My rest API looks something like this</p>
  
  <pre><code>String url = new StringBuilder(urlConfigService.getProfiles().getBaseUrl()).append(relativeUrl).toString();
      **String hiddenAccess = "ASHGHGHJ:HVRid992Xl740NnWOkjk";**
  
      // @formatter:off
      UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
              .queryParam("refEboard", refEboard)
              .queryParam("idLangue", "FR");
      // @formatter:on
  
      HttpHeaders requestHeaders = new HttpHeaders();
      requestHeaders.setContentType(MediaType.APPLICATION_JSON);
      requestHeaders.add("Authorization", hiddenAccess);
      HttpEntity&lt;?&gt; httpEntity = new HttpEntity&lt;String&gt;(requestHeaders);
      restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
      String result =
          restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, httpEntity, String.class).getBody();
      return (T) new Gson().fromJson(result, type.getClass());
  </code></pre>