You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by "Mills, Nick" <Ni...@travelocity.com> on 2010/10/28 02:53:56 UTC

how to force basic scheme authentication using HttpClient 4.0.2

I don't want to authenticate with the proxy using NTLM v2 (because it's not supported).
So is there a way to force basic authentication in 4.0.2?

I'm stuck with the 4.0.2 version because I'm using WebDriver 2.0a6.

For older 3.x HttpClients we could do:

HttpClient client = new HttpClient();
List authPrefs = new ArrayList(2);
authPrefs.add(AuthPolicy.DIGEST);
authPrefs.add(AuthPolicy.BASIC);
// This will exclude the NTLM authentication scheme
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);

Am I able to do something similar with 4.0.2?

Thanks,
Nick Mills

RE: how to force basic scheme authentication using HttpClient 4.0.2

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2010-10-28 at 16:33 -0500, Mills, Nick wrote:
> Thanks Oleg,
> Works like a charm. I noticed that if I leave the scheme preferences alone it tries to authenticate with NTLM then falls back to basic anyway. I don't remember HttpClient 3.x doing this, is this new in HttpClient?
> 
> cheers,
> Nick
> 

Nick

I think HC 3.x should behave exactly the same way if the NTLM were
disabled. If the target server sends two challenges NTLM and BASIC back
and NTLM is not supported or disabled, BASIC will be used as a fall
back.

Hope this helps

Oleg

> -----Original Message-----
> From: Oleg Kalnichevski [mailto:olegk@apache.org] 
> Sent: Thursday, October 28, 2010 10:50 AM
> To: HttpClient User Discussion
> Subject: Re: how to force basic scheme authentication using HttpClient 4.0.2
> 
> On Wed, 2010-10-27 at 19:53 -0500, Mills, Nick wrote:
> > I don't want to authenticate with the proxy using NTLM v2 (because it's not supported).
> > So is there a way to force basic authentication in 4.0.2?
> > 
> > I'm stuck with the 4.0.2 version because I'm using WebDriver 2.0a6.
> > 
> > For older 3.x HttpClients we could do:
> > 
> > HttpClient client = new HttpClient();
> > List authPrefs = new ArrayList(2);
> > authPrefs.add(AuthPolicy.DIGEST);
> > authPrefs.add(AuthPolicy.BASIC);
> > // This will exclude the NTLM authentication scheme
> > client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
> > 
> > Am I able to do something similar with 4.0.2?
> > 
> 
> Yes, you can
> 
> With HttpClient 4.0.x one can override the
> AbstractAuthenticationHandler#getAuthPreferences() method in order to
> return a different sequence of preferred auth schemes
> 
> With HttpClient 4.1-alpha-x one can also use
> 'http.auth.proxy-scheme-perf' and 'http.auth.target-scheme-perf'
> parameters to set a particular sequence of preferred auth schemes for
> proxy and target authentication respectively.
> 
> Please also note HttpClient 4.1 HEAD (to be released as 4.1-beta1 soon)
> fully supports NTLMv1 and NTLMv2 auth schemes out of the box
> 
> Hope this help
> 
> Oleg 
> 
> > Thanks,
> > Nick Mills
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


RE: how to force basic scheme authentication using HttpClient 4.0.2

Posted by "Mills, Nick" <Ni...@travelocity.com>.
Thanks Oleg,
Works like a charm. I noticed that if I leave the scheme preferences alone it tries to authenticate with NTLM then falls back to basic anyway. I don't remember HttpClient 3.x doing this, is this new in HttpClient?

cheers,
Nick

-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@apache.org] 
Sent: Thursday, October 28, 2010 10:50 AM
To: HttpClient User Discussion
Subject: Re: how to force basic scheme authentication using HttpClient 4.0.2

On Wed, 2010-10-27 at 19:53 -0500, Mills, Nick wrote:
> I don't want to authenticate with the proxy using NTLM v2 (because it's not supported).
> So is there a way to force basic authentication in 4.0.2?
> 
> I'm stuck with the 4.0.2 version because I'm using WebDriver 2.0a6.
> 
> For older 3.x HttpClients we could do:
> 
> HttpClient client = new HttpClient();
> List authPrefs = new ArrayList(2);
> authPrefs.add(AuthPolicy.DIGEST);
> authPrefs.add(AuthPolicy.BASIC);
> // This will exclude the NTLM authentication scheme
> client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
> 
> Am I able to do something similar with 4.0.2?
> 

Yes, you can

With HttpClient 4.0.x one can override the
AbstractAuthenticationHandler#getAuthPreferences() method in order to
return a different sequence of preferred auth schemes

With HttpClient 4.1-alpha-x one can also use
'http.auth.proxy-scheme-perf' and 'http.auth.target-scheme-perf'
parameters to set a particular sequence of preferred auth schemes for
proxy and target authentication respectively.

Please also note HttpClient 4.1 HEAD (to be released as 4.1-beta1 soon)
fully supports NTLMv1 and NTLMv2 auth schemes out of the box

Hope this help

Oleg 

> Thanks,
> Nick Mills



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: how to force basic scheme authentication using HttpClient 4.0.2

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2010-10-27 at 19:53 -0500, Mills, Nick wrote:
> I don't want to authenticate with the proxy using NTLM v2 (because it's not supported).
> So is there a way to force basic authentication in 4.0.2?
> 
> I'm stuck with the 4.0.2 version because I'm using WebDriver 2.0a6.
> 
> For older 3.x HttpClients we could do:
> 
> HttpClient client = new HttpClient();
> List authPrefs = new ArrayList(2);
> authPrefs.add(AuthPolicy.DIGEST);
> authPrefs.add(AuthPolicy.BASIC);
> // This will exclude the NTLM authentication scheme
> client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
> 
> Am I able to do something similar with 4.0.2?
> 

Yes, you can

With HttpClient 4.0.x one can override the
AbstractAuthenticationHandler#getAuthPreferences() method in order to
return a different sequence of preferred auth schemes

With HttpClient 4.1-alpha-x one can also use
'http.auth.proxy-scheme-perf' and 'http.auth.target-scheme-perf'
parameters to set a particular sequence of preferred auth schemes for
proxy and target authentication respectively.

Please also note HttpClient 4.1 HEAD (to be released as 4.1-beta1 soon)
fully supports NTLMv1 and NTLMv2 auth schemes out of the box

Hope this help

Oleg 

> Thanks,
> Nick Mills



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: how to force basic scheme authentication using HttpClient 4.0.2

Posted by Abhishek Rakshit <ab...@architexa.com>.
Hey Nick,

This is what I do for the basic authentication for my application. Hope this
helps.
-------------------------

private static void setAuthentication(DefaultHttpClient httpClient,
HttpRequest methodReq, Credentials credentials, AuthScope authScope) {

 httpClient.getCredentialsProvider().setCredentials(authScope, credentials);

 BasicScheme basicAuth = new BasicScheme();

 try {

 Header authHeader = basicAuth.authenticate(credentials, methodReq);

 methodReq.addHeader(authHeader);

 } catch (AuthenticationException e) {

 e.printStackTrace();

 }

}

---------------


On Wed, Oct 27, 2010 at 8:53 PM, Mills, Nick <Ni...@travelocity.com>wrote:

> I don't want to authenticate with the proxy using NTLM v2 (because it's not
> supported).
> So is there a way to force basic authentication in 4.0.2?
>
> I'm stuck with the 4.0.2 version because I'm using WebDriver 2.0a6.
>
> For older 3.x HttpClients we could do:
>
> HttpClient client = new HttpClient();
> List authPrefs = new ArrayList(2);
> authPrefs.add(AuthPolicy.DIGEST);
> authPrefs.add(AuthPolicy.BASIC);
> // This will exclude the NTLM authentication scheme
> client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
> authPrefs);
>
> Am I able to do something similar with 4.0.2?
>
> Thanks,
> Nick Mills
>



-- 
Regards,
Abhishek Rakshit
abhishek@architexa.com: (785)214-1324
www.architexa.com