in httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/SystemDefaultCredentialsProvider.java [100:140]
public Credentials getCredentials(final AuthScope authScope, final HttpContext context) {
Args.notNull(authScope, "Auth scope");
final Credentials localcreds = internal.getCredentials(authScope, context);
if (localcreds != null) {
return localcreds;
}
final String host = authScope.getHost();
if (host != null) {
final HttpClientContext clientContext = context != null ? HttpClientContext.adapt(context) : null;
final String protocol = authScope.getProtocol() != null ? authScope.getProtocol() : (authScope.getPort() == 443 ? URIScheme.HTTPS.id : URIScheme.HTTP.id);
PasswordAuthentication systemcreds = getSystemCreds(
protocol, authScope, Authenticator.RequestorType.SERVER, clientContext);
if (systemcreds == null) {
systemcreds = getSystemCreds(
protocol, authScope, Authenticator.RequestorType.PROXY, clientContext);
}
if (systemcreds == null) {
// 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(URIScheme.HTTP.getId(), authScope);
if (systemcreds == null) {
systemcreds = getProxyCredentials(URIScheme.HTTPS.getId(), authScope);
}
}
if (systemcreds != null) {
final String domain = System.getProperty("http.auth.ntlm.domain");
if (domain != null) {
return new NTCredentials(systemcreds.getUserName(), systemcreds.getPassword(), null, domain);
}
if (StandardAuthScheme.NTLM.equalsIgnoreCase(authScope.getSchemeName())) {
// Domain may be specified in a fully qualified user name
return new NTCredentials(
systemcreds.getUserName(), systemcreds.getPassword(), null, null);
}
return new UsernamePasswordCredentials(systemcreds.getUserName(), systemcreds.getPassword());
}
}
return null;
}