|
46 | 46 | import org.apache.http.auth.Credentials;
|
47 | 47 | import org.apache.http.auth.NTCredentials;
|
48 | 48 | import org.apache.http.auth.UsernamePasswordCredentials;
|
| 49 | +import org.apache.http.client.AuthCache; |
49 | 50 | import org.apache.http.client.CredentialsProvider;
|
50 | 51 | import org.apache.http.client.HttpClient;
|
51 | 52 | import org.apache.http.client.config.RequestConfig;
|
52 | 53 | import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
53 | 54 | import org.apache.http.client.methods.HttpRequestBase;
|
54 | 55 | import org.apache.http.client.params.AuthPolicy;
|
55 | 56 | import org.apache.http.client.protocol.HttpClientContext;
|
| 57 | +import org.apache.http.impl.auth.BasicScheme; |
| 58 | +import org.apache.http.impl.client.BasicAuthCache; |
56 | 59 | import org.apache.http.impl.client.BasicCredentialsProvider;
|
57 | 60 | import org.apache.http.util.EntityUtils;
|
58 | 61 |
|
@@ -314,5 +317,15 @@ public void enableAuthentication(HTTPAuthenticator authenticator) {
|
314 | 317 | }
|
315 | 318 | requestConfig.setTargetPreferredAuthSchemes(authPrefs);
|
316 | 319 | }
|
| 320 | + |
| 321 | + if (authenticator.getPreemptiveAuthentication() && host != null) { |
| 322 | + //Use authCache - could also set header |
| 323 | + AuthCache authCache = clientContext.getAuthCache(); |
| 324 | + if (authCache == null) { |
| 325 | + authCache = new BasicAuthCache(); |
| 326 | + } |
| 327 | + authCache.put(new HttpHost(host), new BasicScheme()); |
| 328 | + clientContext.setAuthCache(authCache); |
| 329 | + } |
317 | 330 | }
|
318 | 331 | }
|
0 commit comments