code: public HttpComponentsClientHttpRequestFactory getObject() throws Exception {
          Assert.notNull(credentials, "User credentials not set properly!");
          
          HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient) {
              @Override
              protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
                  // we have to use preemptive authentication
                  // therefore add some basic auth cache to the local context
                  AuthCache authCache = new BasicAuthCache();
                  BasicScheme basicAuth = new BasicScheme();
                  
                  authCache.put(new HttpHost(authScope.getHost(), authScope.getPort(), "http"), basicAuth);
                  authCache.put(new HttpHost(authScope.getHost(), authScope.getPort(), "https"), basicAuth);
                  
                  BasicHttpContext localcontext = new BasicHttpContext();
                  localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
                  
                  return localcontext;
              }
          };
          
          if (httpClient instanceof AbstractHttpClient) {
              ((AbstractHttpClient)httpClient).getCredentialsProvider().setCredentials(authScope, credentials);
          } else {
              log.warn("Unable to set username password credentials for basic authentication, " +
              		"because nested HttpClient implementation does not support a credentials provider!");
          }
          
          return requestFactory;
      }
docs: Construct the client factory bean with user credentials.