/** * Creates a copy of the given credentials scope. */ public AuthScope(final AuthScope authscope) { super(); Args.notNull(authscope, "Scope"); this.protocol = authscope.getProtocol(); this.host = authscope.getHost(); this.port = authscope.getPort(); this.realm = authscope.getRealm(); this.authScheme = authscope.getAuthScheme(); }
private static PasswordAuthentication getSystemCreds( final String protocol, final AuthScope authscope, final Authenticator.RequestorType requestorType, final HttpClientContext context) { final HttpRequest request = context != null ? context.getRequest() : null; URL targetHostURL; try { final URI uri = request != null ? request.getUri() : null; targetHostURL = uri != null ? uri.toURL() : null; } catch (final URISyntaxException | MalformedURLException ignore) { targetHostURL = null; } // use null addr, because the authentication fails if it does not exactly match the expected realm's host return Authenticator.requestPasswordAuthentication( authscope.getHost(), null, authscope.getPort(), protocol, authscope.getRealm(), translateAuthScheme(authscope.getAuthScheme()), targetHostURL, requestorType); }
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);