title: Spring REST template - 401 Unauthorized error
body: <p>I am using Spring Rest Template inside a Spring Boot Application.</p>
  
  <p>I always get 401 Unauthorized error even though I am passing the credentials.</p>
  
  <p>I am able to access this service by Chrome REST Web Service Client.</p>
  
  <p>Is there a simplified way to access the REST template in SpringBoot.</p>
  
  <p>Below is the code snippet done so far which results in 401 error</p>
  
  <pre><code> private DetailsBean invokeDetailsRestService(UserParam userParam){
      ResponseEntity&lt;DetailsBean&gt; responseEntity = null;
      String url = "https://dev.com/app/identifyuser/";
      RestClientConfig restClientConfig =new RestClientConfig("user123","pass123");
      responseEntity= restClientConfig.postForEntity(url, userParam, DetailsBean.class);
      log.debug("User Details : {} ", responseEntity.getBody());
      return responseEntity.getBody();
  }
  
  public ClientHttpRequestFactory getRequestFactory(String userName,String password){
      CredentialsProvider credsProvider = new BasicCredentialsProvider();
      credsProvider.setCredentials( new AuthScope(null, -1), new UsernamePasswordCredentials(userName,password) );
      HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
      return new HttpComponentsClientHttpRequestFactory(httpClient);
  }
  </code></pre>
  
  <p>RestClientConfig class </p>
  
  <pre><code>  public RestClientConfig(String username, String password) {
      CredentialsProvider credsProvider = new BasicCredentialsProvider();
      credsProvider.setCredentials(
              new AuthScope(null, -1),
              new UsernamePasswordCredentials(username, password));
      HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
      setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>WARN c7af55b5-1cac-4db6-a202-202416c27ba4 
   12612 --- [apr-8082-exec-8] o.a.http.impl.auth.HttpAuthenticator    
  : NEGOTIATE authentication error: 
  No valid credentials provided (Mechanism level: 
  No valid credentials provided (Mechanism level: 
  Failed to find any Kerberos tgt))
  </code></pre>