hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark A. Claassen" <MClaas...@ocie.net>
Subject RE: Proxy with digest authentication
Date Tue, 12 Apr 2016 15:52:49 GMT
I have been working with Proxies as well.  I am no expert, but I think your AuthScope is insufficient.
 

I have a different situation that you do.  I override CredentialsProvider, which I don't think
you need to do, but it does reveal some things when you do it that way.

When an AuthScope comes into getCredentials(AuthScope a); it has a "scheme" associated with
it.  That scheme is matched against other schemes, such as AuthSchemes.DIGEST.  You may be
able to just change your code to create your AuthScope creation to something like:

new AuthScope(new HttpHost("80.1.2.3", 3128), AuthScope.ANY_REALM, AuthScheme.DIGEST)

If not, you can create your own CredentialsProvider.  In the getCredentials() method, you
can verify that it is using a DIGEST scheme and just return the credentials directly, or potentially
put them in a private instance of BasicCredentialsProvider, using the passed in AuthScope
as the parameter to setCredentials().

	public Credentials getCredentials(AuthScope authscope) {
		Credentials rval = delegate.getCredentials(authscope);
		if (rval == null && AuthSchemes.DIGEST.equalsIgnoreCase(scheme)) }
			...
			delegate.setProvider(authscope,rval)
		}
	}

Hope this helps,
Mark


Disclaimer:
The opinions provided herein do not necessarily state or reflect those of Donnell Systems,
Inc.(DSI). DSI makes no warranty for and assumes no legal liability or responsibility for
the posting.

-----Original Message-----
From: Mop Sophia [mailto:mopsophia@gmail.com] 
Sent: Monday, April 11, 2016 12:19 PM
To: httpclient-users@hc.apache.org
Subject: Proxy with digest authentication

Hi,

I try to do a request using a proxy with digest authentication but the authentication fails,
here is the code :

// Proxy credentials
CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new
AuthScope("80.1.2.3", 3128),
        new UsernamePasswordCredentials("proxy_user", "proxy_pass")); HttpHost proxy = new
HttpHost("80.1.2.3", 3128);

CloseableHttpClient httpclient = HttpClients.custom()
        .setSSLSocketFactory(sslsf)
        .setDefaultCredentialsProvider(credsProvider)
        .setProxy(proxy)
        .build();


HttpGet httpget = new HttpGet("https://myhost.com:8443");

HttpClientContext context = HttpClientContext.create();

CloseableHttpResponse resp = httpclient.execute(httpget, context);

Log.d("TST", String.valueOf(resp.getStatusLine()));
Log.d("TST", EntityUtils.toString(resp.getEntity()));

AuthState proxyAuthState = context.getProxyAuthState(); Log.d("TST", "Proxy auth state: "
+ proxyAuthState.getState()); Log.d("TST", "Proxy auth scheme: " + proxyAuthState.getAuthScheme());
Log.d("TST", "Proxy auth credentials: " + proxyAuthState.getCredentials()); AuthState targetAuthState
= context.getTargetAuthState(); Log.d("TST", "Target auth state: " + targetAuthState.getState());
Log.d("TST", "Target auth scheme: " + targetAuthState.getAuthScheme()); Log.d("TST", "Target
auth credentials: " + targetAuthState.getCredentials());




Any idea, please ?

Thanks,

St├ęphane
Mime
View raw message