Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extension-repository-http: implemented HTTP proxy authentification. #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nE0sIghT
Copy link

HttpClientBuilder.useSystemProperties method do not takes into account login and password for authentification against proxy.
This change allows to use http.proxyUser and http.proxyPassword JVM system properties to authentificate against proxy server.

HttpClientBuilder.useSystemProperties method do not takes into account
login and password for authentification against proxy. This change allows
to use http.proxyUser and http.proxyPassword JVM system properties to
authentificate against proxy server.
@tmortagne
Copy link
Member

This looks like a bug on HTTPClient side to me.

@vmassol
Copy link
Member

vmassol commented Mar 23, 2016

Why do you say a bug thomas? The doc at http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/HttpClientBuilder.html clearly lists what it handles and http.proxyPassword and http.proxyUser are not listed. Could be an improvement (although they may have not supported them voluntarily by default) but I don't see why it would be a bug.

@vmassol
Copy link
Member

vmassol commented Mar 23, 2016

Also, even if it were a bug, we still need to work around it.

@tmortagne
Copy link
Member

I say a bug because it does not make much sense for useSystemProperties() to not handled something as standard as http.proxyUser and http.proxyPassword. IMO they were just forgotten and should be reported, if it was on purpose there would be a note about those two properties in the documentation.

@tmortagne
Copy link
Member

Thanks for the contribution @nE0sIghT by the way but I would like to understand why HTTPClient does not support this in the first place before reimplementing on our side the proxy. Also note that this workaround only works for HTTP and not HTTPS proxy from what I understand (at least the standard properties for https are supposed to be https.proxyUser and https.proxyPassword)

@nE0sIghT
Copy link
Author

To say the truth http.proxy(User|Password) never was some standard as I know.
Java documentation only says about http.proxyHost, http.proxyPort and http.nonProxyHosts.
For an example, Liferay uses com.liferay.portal.util.HttpImpl.proxy.(username|password).

I do not think this must be fixed in commons HTTP client.

@tmortagne
Copy link
Member

Java documentation only says about http.proxyHost, http.proxyPort and http.nonProxyHosts.

It also talk about https.proxyHost and https.proxyPort.

For proxyUser the closest from a standard documentation I could find is http://www.ibm.com/support/knowledgecenter/was_beta/com.ibm.websphere.base.doc/ae/twbs_configwbsclient2webproxy.html which is also talking about http.* vs https.*.

}

proxy = new HttpHost(proxyHost, port);
httpClientBuilder.setProxy(proxy);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to me setting the right credential provider should be enough. Setting the proxy is supposed to be useSystemProperties() job, then it will ask the credential provider if it needs authentication.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. However we need to construct proxy HttpHost object to pass it to credential provider.
This part is not clear for me if auto detected system proxy used.
I think the proper way is to extract all auto detected system proxies (as commons HTTP client do it) and set credentials for each of them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A much simpler alternative to all that might be to just set a default java.net.Authenticator which return whatever is indicated in http.proxyUser/Pass if called with RequestorType.PROXY. But probably in a different module since it will apply to everything so that you can get rid of it if you want to provide a different one for your setup.

Others had this idea. For inspiration on how to implement it: https://svn.apache.org/repos/asf/ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/IvyAuthenticator.java

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice! I think this is a best method.

@sdumitriu
Copy link
Member

@nE0sIghT
Copy link
Author

@sdumitriu
As I see this implementation wil reveal proxy login/password to any website. At least getRequestorType method should be used.

@sdumitriu
Copy link
Member

@nE0sIghT True, but the example is how this could be accomplished globally, not just for extension-repository-http, and in a manner that doesn't add complexity. The authenticator itself is as simple as possible, and it should indeed check the authenticator type, and could be extended to take into account different http and https settings.

@tmortagne
Copy link
Member

Yep this is a good illustration of what I was talking about, plus it's already XWiki style :)

But this one is missing a few things IMO:

  • it should wrap any pre existing default Authenticator (and put it back in the dispose() of the listener probably)
  • it should return the login/password only if the type is PROXY, otherwise fallback on wrapped Authenticator
  • it should also support https.proxyUser/Passwor IMO since I saw several mentions of this around (and they make sense anyway since that's how proxy host and ports are working too)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants