ok2c closed pull request #123: Better handling of http(s).proxyUser and
http(s).proxyPassword
URL: https://github.com/apache/httpcomponents-client/pull/123
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java
b/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java
index 3ac37f6a5..4f7545005 100644
---
a/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java
+++
b/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java
@@ -117,22 +117,13 @@ public Credentials getCredentials(final AuthScope
authscope) {
systemcreds = getSystemCreds(protocol, authscope,
Authenticator.RequestorType.PROXY);
}
if (systemcreds == null) {
- final String proxyHost = System.getProperty(protocol +
".proxyHost");
- if (proxyHost != null) {
- final String proxyPort = System.getProperty(protocol +
".proxyPort");
- if (proxyPort != null) {
- try {
- final AuthScope systemScope = new
AuthScope(proxyHost, Integer.parseInt(proxyPort));
- if (authscope.match(systemScope) >= 0) {
- final String proxyUser =
System.getProperty(protocol + ".proxyUser");
- if (proxyUser != null) {
- final String proxyPassword =
System.getProperty(protocol + ".proxyPassword");
- systemcreds = new
PasswordAuthentication(proxyUser, proxyPassword != null ?
proxyPassword.toCharArray() : new char[] {});
- }
- }
- } catch (final NumberFormatException ex) {
- }
- }
+ // Look for values given using
http.proxyUser/http.proxyPassword or
+ // https.proxyUser/https.proxyPassword. We cannot simply use
the protocol from
+ // the origin since a proxy retrieved from
https.proxyHost/https.proxyPort will
+ // still use http as protocol
+ systemcreds = getProxyCredentials("http", authscope);
+ if (systemcreds == null) {
+ systemcreds = getProxyCredentials("https", authscope);
}
}
if (systemcreds != null) {
@@ -154,6 +145,34 @@ public Credentials getCredentials(final AuthScope
authscope) {
return null;
}
+ private static PasswordAuthentication getProxyCredentials(final String
protocol, final AuthScope authscope) {
+ final String proxyHost = System.getProperty(protocol + ".proxyHost");
+ if (proxyHost == null) {
+ return null;
+ }
+ final String proxyPort = System.getProperty(protocol + ".proxyPort");
+ if (proxyPort == null) {
+ return null;
+ }
+
+ try {
+ final AuthScope systemScope = new AuthScope(proxyHost,
Integer.parseInt(proxyPort));
+ if (authscope.match(systemScope) >= 0) {
+ final String proxyUser = System.getProperty(protocol +
".proxyUser");
+ if (proxyUser == null) {
+ return null;
+ }
+ final String proxyPassword = System.getProperty(protocol +
".proxyPassword");
+
+ return new PasswordAuthentication(proxyUser,
+ proxyPassword != null ? proxyPassword.toCharArray() :
new char[] {});
+ }
+ } catch (final NumberFormatException ex) {
+ }
+
+ return null;
+ }
+
@Override
public void clear() {
internal.clear();
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]