@@ -106,54 +106,15 @@ public Credentials getCredentials(final AuthScope authScope, final HttpContext c
106106 if (host != null ) {
107107 final HttpClientContext clientContext = context != null ? HttpClientContext .cast (context ) : null ;
108108 final String protocol = authScope .getProtocol () != null ? authScope .getProtocol () : (authScope .getPort () == 443 ? URIScheme .HTTPS .id : URIScheme .HTTP .id );
109- PasswordAuthentication systemcreds = getSystemCreds (
110- protocol , authScope , Authenticator .RequestorType .SERVER , clientContext );
111- if (systemcreds == null ) {
112- systemcreds = getSystemCreds (
113- protocol , authScope , Authenticator .RequestorType .PROXY , clientContext );
109+ final PasswordAuthentication serverCreds = getSystemCreds (protocol , authScope , Authenticator .RequestorType .SERVER , clientContext );
110+ if (serverCreds != null ) {
111+ return new UsernamePasswordCredentials (serverCreds .getUserName (), serverCreds .getPassword ());
114112 }
115- if (systemcreds == null ) {
116- // Look for values given using http.proxyUser/http.proxyPassword or
117- // https.proxyUser/https.proxyPassword. We cannot simply use the protocol from
118- // the origin since a proxy retrieved from https.proxyHost/https.proxyPort will
119- // still use http as protocol
120- systemcreds = getProxyCredentials (URIScheme .HTTP .getId (), authScope );
121- if (systemcreds == null ) {
122- systemcreds = getProxyCredentials (URIScheme .HTTPS .getId (), authScope );
123- }
113+ final PasswordAuthentication proxyCreds = getSystemCreds (protocol , authScope , Authenticator .RequestorType .PROXY , clientContext );
114+ if (proxyCreds != null ) {
115+ return new UsernamePasswordCredentials (proxyCreds .getUserName (), proxyCreds .getPassword ());
124116 }
125- if (systemcreds != null ) {
126- return new UsernamePasswordCredentials (systemcreds .getUserName (), systemcreds .getPassword ());
127- }
128- }
129- return null ;
130- }
131-
132- private static PasswordAuthentication getProxyCredentials (final String protocol , final AuthScope authScope ) {
133- final String proxyHost = System .getProperty (protocol + ".proxyHost" );
134- if (proxyHost == null ) {
135- return null ;
136- }
137- final String proxyPort = System .getProperty (protocol + ".proxyPort" );
138- if (proxyPort == null ) {
139- return null ;
140117 }
141-
142- try {
143- final AuthScope systemScope = new AuthScope (proxyHost , Integer .parseInt (proxyPort ));
144- if (authScope .match (systemScope ) >= 0 ) {
145- final String proxyUser = System .getProperty (protocol + ".proxyUser" );
146- if (proxyUser == null ) {
147- return null ;
148- }
149- final String proxyPassword = System .getProperty (protocol + ".proxyPassword" );
150-
151- return new PasswordAuthentication (proxyUser ,
152- proxyPassword != null ? proxyPassword .toCharArray () : new char [] {});
153- }
154- } catch (final NumberFormatException ignore ) {
155- }
156-
157118 return null ;
158119 }
159120
0 commit comments