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 Justin Tay <ju...@gmail.com> on 2008/08/04 17:02:22 UTC

Proxy Authentication

Hi,

I would like to do the following regarding proxy authentication.

1) Pre-emptive authentication for proxies that have issued a challenge
before. (The idea being that a proxy that has requested for authentication
before will probably still ask for authentication)
2) Allow the handling of failed authentication requests due to incorrect
credentials. (The use case is similar to what happens when the proxy
credentials are wrong in a browser, it will prompt the user for a username
and password and try to authenticate with the proxy again)

For (1) followed the sample that implements HttpRequestInterceptor and was
able to meet the requirement by implementing HttpResponseInterceptor and
storing the HttpHost of the proxy and AuthScheme into a map to be retrieved
later. (BasicScheme only knows it's handling a proxy after a call to
processChallenge). This works fine when connecting to http targets. 

However I would also like this behaviour to apply when connecting to https
targets. I notice that this is done in
DefaultRequestDirector.createTunnelToTarget() and doesn't involve the
calling of any interceptors. In any case the execution context isn't
populated till later.

Is there any way to achieve this without extending DefaultRequestDirector?

For (2) is it possible to add one more method to the AuthenticationHandler
like handleAuthenticationFailure? My only other alternative seems to be
extending DefaultRequestDirector and overriding the updateAuthState method.
I think it's best if in additional to the proxyAuthHandler, the
targetAuthHandler can also use this to prompt the user for credentials again
if the user gets it wrong.

Regards,
Justin Tay
-- 
View this message in context: http://www.nabble.com/Proxy-Authentication-tp18813008p18813008.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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


Re: Proxy Authentication

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2008-08-05 at 15:52 -0700, Justin Tay wrote:
> Hi Oleg,
> 
> > The fact that protocol interceptors do not get called when executing 
> > CONNECT methods is clearly a bug. Please open a JIRA issue for this 
> > problem. Preemptive authentication should work for tunneled connections 
> > exactly the same way for the direct ones.
> 
> Have opened an issue for this on JIRA.
> 
> >This is intentional. Execution of potentially blocking operations such 
> >as UI dialogs inside the main request execution loops is a bad idea, 
> >because such blocking operations will prevent the connection from being 
> >returned to the connection manager for a long period of time. 
> 
> I've ended up subclassing the DefaultRequestDirector as I want some
> automated handling of this but I'm not sure if there are any issues in my
> implementation. Could you have a quick look and see if there's anything I've
> failed to take into account? Thanks!
> 
> http://gemz.org/temp/httpclient/InteractiveAuthenticationRequestDirector.java
> http://gemz.org/temp/httpclient/InteractiveAuthenticationHandler.java
> http://gemz.org/temp/httpclient/InteractiveProxyAuthenticationHandler.java
> 

Hi Justin

I took a (cursory) look at the code and found no obvious problems with
it. All seemed okay to me.

Oleg



> >> Hope this helps
> 
> You've been a great help and I'm impressed with the design of the library.
> Thanks!
> 
> Regards,
> Justin Tay


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


Re: Proxy Authentication

Posted by Justin Tay <ju...@gmail.com>.
Hi Oleg,

> The fact that protocol interceptors do not get called when executing 
> CONNECT methods is clearly a bug. Please open a JIRA issue for this 
> problem. Preemptive authentication should work for tunneled connections 
> exactly the same way for the direct ones.

Have opened an issue for this on JIRA.

>This is intentional. Execution of potentially blocking operations such 
>as UI dialogs inside the main request execution loops is a bad idea, 
>because such blocking operations will prevent the connection from being 
>returned to the connection manager for a long period of time. 

I've ended up subclassing the DefaultRequestDirector as I want some
automated handling of this but I'm not sure if there are any issues in my
implementation. Could you have a quick look and see if there's anything I've
failed to take into account? Thanks!

http://gemz.org/temp/httpclient/InteractiveAuthenticationRequestDirector.java
http://gemz.org/temp/httpclient/InteractiveAuthenticationHandler.java
http://gemz.org/temp/httpclient/InteractiveProxyAuthenticationHandler.java

>> Hope this helps

You've been a great help and I'm impressed with the design of the library.
Thanks!

Regards,
Justin Tay
-- 
View this message in context: http://www.nabble.com/Proxy-Authentication-tp18813008p18841433.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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


Re: Proxy Authentication

Posted by Oleg Kalnichevski <ol...@apache.org>.
Justin Tay wrote:
> Hi,
>
> I would like to do the following regarding proxy authentication.
>
> 1) Pre-emptive authentication for proxies that have issued a challenge
> before. (The idea being that a proxy that has requested for authentication
> before will probably still ask for authentication)
> 2) Allow the handling of failed authentication requests due to incorrect
> credentials. (The use case is similar to what happens when the proxy
> credentials are wrong in a browser, it will prompt the user for a username
> and password and try to authenticate with the proxy again)
>
> For (1) followed the sample that implements HttpRequestInterceptor and was
> able to meet the requirement by implementing HttpResponseInterceptor and
> storing the HttpHost of the proxy and AuthScheme into a map to be retrieved
> later. (BasicScheme only knows it's handling a proxy after a call to
> processChallenge). This works fine when connecting to http targets. 
>
> However I would also like this behaviour to apply when connecting to https
> targets. I notice that this is done in
> DefaultRequestDirector.createTunnelToTarget() and doesn't involve the
> calling of any interceptors. In any case the execution context isn't
> populated till later.
>
>   
Justin,

The fact that protocol interceptors do not get called when executing 
CONNECT methods is clearly a bug. Please open a JIRA issue for this 
problem. Preemptive authentication should work for tunneled connections 
exactly the same way for the direct ones.

> Is there any way to achieve this without extending DefaultRequestDirector?
>
> For (2) is it possible to add one more method to the AuthenticationHandler
> like handleAuthenticationFailure? My only other alternative seems to be
> extending DefaultRequestDirector and overriding the updateAuthState method.
> I think it's best if in additional to the proxyAuthHandler, the
> targetAuthHandler can also use this to prompt the user for credentials again
> if the user gets it wrong.
>
>   
This is intentional. Execution of potentially blocking operations such 
as UI dialogs inside the main request execution loops is a bad idea, 
because such blocking operations will prevent the connection from being 
returned to the connection manager for a long period of time. 
Interactive user authentication should be implemented on top of 
HttpClient services: the caller should detect 401 and 407 status codes, 
pop a UI dialog, collect new credentials, update credentials in the 
actual CredentialsStore, and retry the request.

Hope this helps

Oleg

> Regards,
> Justin Tay
>   


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