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 John Watson <JW...@sis.tv> on 2009/03/30 12:48:18 UTC

Help with basic authentication

I'm a new user of Http Client 4.0 (beta 2) and I'm struggling with BASIC
authentication.  I'm attempting to follow the authentication sample
using (simply):

 

        httpclient.getCredentialsProvider().setCredentials(

                new AuthScope(realm, port),

                new UsernamePasswordCredentials(userName, password));

 

Firstly, I can't seem to set pre-emptive authentication using as a guide
the sample from http://hc.apache.org/httpclient-3.x/authentication.html
- I can't seem to find the method
client.getParams().setAuthenticationPreemptive(...);
 
Secondly, from inspecting the logs issued by the client, it appears that
the authorization request header that I'd expect to see is not there.
 
I'm obviously missing something obvious, but for the life of me, can't
find what it is.  Any help gratefully accepted.
 
John Watson
 
 

 


**********************************************************************
Satellite Information Services Limited. Registered Office: 17 Corsham Street, London, N1 6DR. Company No. 4243307
The information in this email (which includes any files transmitted with it) is confidential and is intended for the addressee only. Unauthorized recipients are required to maintain confidentiality. If you have received this email in error please notify the sender immediately, destroy any copies and delete it from your computer system.
**********************************************************************


Re: Help with basic authentication

Posted by Oleg Kalnichevski <ol...@apache.org>.
John Watson wrote:
> Thanks very much, Oleg - that was a great help.  The host name (not
> realm) was the major problem.  Also I hadn't realized that links in the
> web site that explained authorization were only available for the older
> version.  Will these be updated at some stage to v4?
> 

I am working on documentation for 4.0 API

http://wiki.apache.org/HttpComponents/HttpClientTutorial

Help and contributions would be _very_ welcome.

Oleg


> Cheers
> 
> John
> 
> -----Original Message-----
> From: Oleg Kalnichevski [mailto:olegk@apache.org] 
> Sent: 30 March 2009 12:31
> To: HttpClient User Discussion
> Subject: Re: Help with basic authentication
> 
> John Watson wrote:
>> I'm a new user of Http Client 4.0 (beta 2) and I'm struggling with
> BASIC
>> authentication.  I'm attempting to follow the authentication sample
>> using (simply):
>>
>>  
>>
>>         httpclient.getCredentialsProvider().setCredentials(
>>
>>                 new AuthScope(realm, port),
>>
>>                 new UsernamePasswordCredentials(userName, password));
>>
>>  
>>
>> Firstly, I can't seem to set pre-emptive authentication using as a
> guide
>> the sample from
> http://hc.apache.org/httpclient-3.x/authentication.html
>> - I can't seem to find the method
>> client.getParams().setAuthenticationPreemptive(...);
>>  
> 
> Preemptive authentication in HttpClient 4.0 works completely differently
> 
> compared to 3.x.
> 
> Here's a sample application showing how HttpClient can be customized to 
> authenticate preemptively using BASIC scheme
> 
> http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclie
> nt/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAut
> hentication.java
> 
>> Secondly, from inspecting the logs issued by the client, it appears
> that
>> the authorization request header that I'd expect to see is not there.
>>  
> 
> Most likely the auth scope is wrong
> 
> ---
> new AuthScope(realm, port)
> ---
> 
> The fist argument is hostname, not realm
> 
> Hope this helps
> 
> Oleg
> 
> 
>> I'm obviously missing something obvious, but for the life of me, can't
>> find what it is.  Any help gratefully accepted.
>>  
>> John Watson
>>  
>>  
>>
>>  
>>
>>
>> **********************************************************************
>> Satellite Information Services Limited. Registered Office: 17 Corsham
> Street, London, N1 6DR. Company No. 4243307
>> The information in this email (which includes any files transmitted
> with it) is confidential and is intended for the addressee only.
> Unauthorized recipients are required to maintain confidentiality. If you
> have received this email in error please notify the sender immediately,
> destroy any copies and delete it from your computer system.
>> **********************************************************************
>>
>>
> 
> 
> ---------------------------------------------------------------------
> 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
> 


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


RE: Help with basic authentication

Posted by John Watson <JW...@sis.tv>.
Thanks very much, Oleg - that was a great help.  The host name (not
realm) was the major problem.  Also I hadn't realized that links in the
web site that explained authorization were only available for the older
version.  Will these be updated at some stage to v4?

Cheers

John

-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@apache.org] 
Sent: 30 March 2009 12:31
To: HttpClient User Discussion
Subject: Re: Help with basic authentication

John Watson wrote:
> I'm a new user of Http Client 4.0 (beta 2) and I'm struggling with
BASIC
> authentication.  I'm attempting to follow the authentication sample
> using (simply):
> 
>  
> 
>         httpclient.getCredentialsProvider().setCredentials(
> 
>                 new AuthScope(realm, port),
> 
>                 new UsernamePasswordCredentials(userName, password));
> 
>  
> 
> Firstly, I can't seem to set pre-emptive authentication using as a
guide
> the sample from
http://hc.apache.org/httpclient-3.x/authentication.html
> - I can't seem to find the method
> client.getParams().setAuthenticationPreemptive(...);
>  

Preemptive authentication in HttpClient 4.0 works completely differently

compared to 3.x.

Here's a sample application showing how HttpClient can be customized to 
authenticate preemptively using BASIC scheme

http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclie
nt/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAut
hentication.java

> Secondly, from inspecting the logs issued by the client, it appears
that
> the authorization request header that I'd expect to see is not there.
>  

Most likely the auth scope is wrong

---
new AuthScope(realm, port)
---

The fist argument is hostname, not realm

Hope this helps

Oleg


> I'm obviously missing something obvious, but for the life of me, can't
> find what it is.  Any help gratefully accepted.
>  
> John Watson
>  
>  
> 
>  
> 
> 
> **********************************************************************
> Satellite Information Services Limited. Registered Office: 17 Corsham
Street, London, N1 6DR. Company No. 4243307
> The information in this email (which includes any files transmitted
with it) is confidential and is intended for the addressee only.
Unauthorized recipients are required to maintain confidentiality. If you
have received this email in error please notify the sender immediately,
destroy any copies and delete it from your computer system.
> **********************************************************************
> 
> 


---------------------------------------------------------------------
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: Help with basic authentication

Posted by Oleg Kalnichevski <ol...@apache.org>.
John Watson wrote:
> I'm a new user of Http Client 4.0 (beta 2) and I'm struggling with BASIC
> authentication.  I'm attempting to follow the authentication sample
> using (simply):
> 
>  
> 
>         httpclient.getCredentialsProvider().setCredentials(
> 
>                 new AuthScope(realm, port),
> 
>                 new UsernamePasswordCredentials(userName, password));
> 
>  
> 
> Firstly, I can't seem to set pre-emptive authentication using as a guide
> the sample from http://hc.apache.org/httpclient-3.x/authentication.html
> - I can't seem to find the method
> client.getParams().setAuthenticationPreemptive(...);
>  

Preemptive authentication in HttpClient 4.0 works completely differently 
compared to 3.x.

Here's a sample application showing how HttpClient can be customized to 
authenticate preemptively using BASIC scheme

http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java

> Secondly, from inspecting the logs issued by the client, it appears that
> the authorization request header that I'd expect to see is not there.
>  

Most likely the auth scope is wrong

---
new AuthScope(realm, port)
---

The fist argument is hostname, not realm

Hope this helps

Oleg


> I'm obviously missing something obvious, but for the life of me, can't
> find what it is.  Any help gratefully accepted.
>  
> John Watson
>  
>  
> 
>  
> 
> 
> **********************************************************************
> Satellite Information Services Limited. Registered Office: 17 Corsham Street, London, N1 6DR. Company No. 4243307
> The information in this email (which includes any files transmitted with it) is confidential and is intended for the addressee only. Unauthorized recipients are required to maintain confidentiality. If you have received this email in error please notify the sender immediately, destroy any copies and delete it from your computer system.
> **********************************************************************
> 
> 


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