[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-1412?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13786682#comment-13786682
 ] 

Mike Youngstrom edited comment on HTTPCLIENT-1412 at 10/4/13 10:10 PM:
-----------------------------------------------------------------------

Thanks Oleg,  I tried the latest snapshot and it doesn't solve the problem 
given my current Authenticator.getPasswordAuthentication() implementation.  I 
do think your idea to execute Authenticator.getPasswordAuthentication() twice 
would work.

You also bring up a good point about host and port being unique enough.  I 
cannot think of any case where I really need to check the requestor type.  I'll 
probably just remove the RequestorType check in my authenticator.

If you changed the code to invoke requestPasswordAuthentication twice like you 
say it might help others with Authenticators written similar to mine.  I'll let 
you decide if you want to make that change or not.  I think I'll be fine either 
way.

Thanks for the prompt response to this issue!

Mike


was (Author: youngm):
Thanks Oleg,  I tried the latest snapshot and it doesn't solve the problem 
given my current Authenticator.getPasswordAuthentication() implementation.  I 
do think your idea to execute Authenticator.getPasswordAuthentication() twice 
would work.

You also bring up a good point about host and port being unique enough.  I 
cannot think of any case where I really need to check the authenticator type.  
I'll probably just remove the RequestorType check in my authenticator.

If you changed the code to invoke requestPasswordAuthentication twice like you 
say it might help others with Authenticators written similar to mine.  I'll let 
you decide if you want to make that change or not.  I think I'll be fine either 
way.

Thanks for the prompt response to this issue!

Mike

> SystemDefaultCredentialsProvider doesn't specify RequestorType.PROXY for 
> proxy authentication requests
> ------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1412
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1412
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.3 Final
>            Reporter: Mike Youngstrom
>            Priority: Minor
>             Fix For: 4.3.2
>
>
> I have a custom java.net.Authenticator that uses system properties to provide 
> authentication for proxy requests.  When using 
> SystemDefaultCredentialsProvider with useSystemProperties() my custom 
> authenticator doesn't work because the getRequestorType() is set to SERVER 
> and not PROXY as it should be for a proxy auth request.
> Below is a simple test case that illustrates the problem if you have a proxy 
> that requires basic auth that you can connect to.
> {code:java}
>       public static void main(String[] args) throws Exception {
>               System.setProperty("http.proxyHost", "some.basic.auth.proxy");
>               System.setProperty("http.proxyPort", "1080");
>               System.setProperty("http.proxyUser", "someUser");
>               System.setProperty("http.proxyPassword", "somePassword");
>               Authenticator.setDefault(new Authenticator() {
>                       protected PasswordAuthentication 
> getPasswordAuthentication() {
>                               //getRequestorType() == SERVER not PROXY
>                               if (getRequestorType() == RequestorType.PROXY) {
>                                       String prot = 
> getRequestingProtocol().toLowerCase();
>                                       String host = System.getProperty(prot + 
> ".proxyHost", "");
>                                       String port = System.getProperty(prot + 
> ".proxyPort", "");
>                                       String user = System.getProperty(prot + 
> ".proxyUser", "");
>                                       String password = 
> System.getProperty(prot + ".proxyPassword", "");
>                                       if 
> (getRequestingHost().equalsIgnoreCase(host)) {
>                                               if (Integer.parseInt(port) == 
> getRequestingPort()) {
>                                                       // We're connecting to 
> the proxy.  Go ahead and send credentials.
>                                                       return new 
> PasswordAuthentication(user,
>                                                                       
> password.toCharArray());
>                                               }
>                                       }
>                               }
>                               return null;
>                       }
>               });
>               HttpClient client = 
> HttpClients.custom().useSystemProperties().build();
>               client.execute(new HttpHost("www.google.com"), new 
> HttpGet("/")).getEntity().writeTo(System.out);
>       }
> {code}



--
This message was sent by Atlassian JIRA
(v6.1#6144)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to