hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ken Krugler <kkrugler_li...@transpac.com>
Subject Re: Preemptive authentication examples wrong
Date Sun, 28 Aug 2011 18:51:52 GMT
Hi Oleg,

We had a situation where we needed to hit a client's test server that would only work with
preemptive authentication.

Below is the code that we wound up using. Given all of the back-and-forth on the list about
this functionality, I'm hoping you can let me know if this is anywhere close...

Thanks!

-- Ken


        HttpRequestInterceptor preemptiveAuth = new HttpRequestInterceptor() {
            public void process(HttpRequest request, HttpContext context) throws HttpException,
IOException {
                AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
                CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
                        ClientContext.CREDS_PROVIDER);
                HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
                
                if (authState.getAuthScheme() == null) {
                    AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
                    Credentials creds = credsProvider.getCredentials(authScope);
                    if (creds != null) {
                        authState.setAuthScheme(new BasicScheme());
                        authState.setCredentials(creds);
                    }
                }
            }
        };

--------------------------
Ken Krugler
+1 530-210-6378
http://bixolabs.com
custom data mining solutions







Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message