public void process(HttpRequest request, HttpContext context)
throws HttpException, IOException {
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
UserPasswordAuthentication creds;
synchronized (this) {
creds = credentials.get(targetHost);
}
if (creds != null) {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(creds.getUsername(),
creds.getPassword());
AuthScope scope = new AuthScope(targetHost);
getHttpClientToDecorate().getCredentialsProvider().setCredentials(scope, credentials);
AuthCache cache = new BasicAuthCache();
cache.put(targetHost, new BasicScheme());
context.setAttribute(ClientContext.AUTH_CACHE, cache);
BasicCredentialsProvider credProvider = new BasicCredentialsProvider();
credProvider.setCredentials(scope, credentials);
context.setAttribute(ClientContext.CREDS_PROVIDER, credProvider);
}
}