public Executor auth(final HttpHost host, final Credentials creds) { return auth(new AuthScope(host), creds); }
/** * 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(); }
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 (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) { return new NTCredentials(systemcreds.getUserName(), systemcreds.getPassword(), null, domain); if (AuthSchemes.NTLM.ident.equalsIgnoreCase(authscope.getAuthScheme())) {
AuthScope bestMatch = null; for (final AuthScope current: map.keySet()) { final int factor = authscope.match(current); if (factor > bestMatchFactor) { bestMatchFactor = factor;
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); }
public Executor authPreemptive(final HttpHost host) { if (this.credentialsStore != null) { final Credentials credentials = this.credentialsStore.getCredentials(new AuthScope(host), null); if (credentials == null) { final BasicScheme basicScheme = new BasicScheme(); basicScheme.initPreemptive(credentials); this.authCache.put(host, basicScheme); } } return this; }
public Executor authPreemptiveProxy(final HttpHost proxy) { if (this.credentialsStore != null) { final Credentials credentials = this.credentialsStore.getCredentials(new AuthScope(proxy), null); if (credentials == null) { final BasicScheme basicScheme = new BasicScheme(); basicScheme.initPreemptive(credentials); this.authCache.put(proxy, basicScheme); } } return this; }
public Executor auth(final HttpHost host, final Credentials creds) { return auth(new AuthScope(host), creds); }
public static void extractFromAuthority( final String scheme, final URIAuthority authority, final CredentialsStore credentialsStore) { Args.notNull(credentialsStore, "Credentials store"); if (authority == null) { return; } final String userinfo = authority.getUserInfo(); if (userinfo == null) { return; } final int atColon = userinfo.indexOf(':'); final String userName; final char[] password; if (atColon >= 0) { userName = userinfo.substring(0, atColon); password = userinfo.substring(atColon + 1).toCharArray(); } else { userName = userinfo.substring(0, atColon); password = null; } credentialsStore.setCredentials( new AuthScope(scheme, authority.getHostName(), authority.getPort(), null, AuthSchemes.BASIC.ident), new UsernamePasswordCredentials(userName, password)); }
public Executor authPreemptiveProxy(final HttpHost proxy) { if (this.credentialsStore != null) { final Credentials credentials = this.credentialsStore.getCredentials(new AuthScope(proxy), null); if (credentials == null) { final BasicScheme basicScheme = new BasicScheme(); basicScheme.initPreemptive(credentials); this.authCache.put(proxy, basicScheme); } } return this; }
public Executor authPreemptive(final HttpHost host) { if (this.credentialsStore != null) { final Credentials credentials = this.credentialsStore.getCredentials(new AuthScope(host), null); if (credentials == null) { final BasicScheme basicScheme = new BasicScheme(); basicScheme.initPreemptive(credentials); this.authCache.put(host, basicScheme); } } return this; }
@Override public boolean isResponseReady( final HttpHost host, final CredentialsProvider credentialsProvider, final HttpContext context) throws AuthenticationException { Args.notNull(host, "Auth host"); Args.notNull(credentialsProvider, "CredentialsProvider"); final Credentials credentials = credentialsProvider.getCredentials( new AuthScope(host, null, getName()), context); if (credentials instanceof NTCredentials) { this.credentials = (NTCredentials) credentials; return true; } return false; }
@Override public boolean isResponseReady( final HttpHost host, final CredentialsProvider credentialsProvider, final HttpContext context) throws AuthenticationException { Args.notNull(host, "Auth host"); Args.notNull(credentialsProvider, "CredentialsProvider"); final Credentials credentials = credentialsProvider.getCredentials( new AuthScope(host, null, getName()), context); if (credentials instanceof KerberosCredentials) { this.gssCredential = ((KerberosCredentials) credentials).getGSSCredential(); } else { this.gssCredential = null; } return true; }
@Override public boolean isResponseReady( final HttpHost host, final CredentialsProvider credentialsProvider, final HttpContext context) throws AuthenticationException { Args.notNull(host, "Auth host"); Args.notNull(credentialsProvider, "CredentialsProvider"); final Credentials credentials = credentialsProvider.getCredentials( new AuthScope(host, getRealm(), getName()), context); if (credentials != null) { this.username = credentials.getUserPrincipal().getName(); this.password = credentials.getPassword(); return true; } this.username = null; this.password = null; return false; }
@Override public boolean isResponseReady( final HttpHost host, final CredentialsProvider credentialsProvider, final HttpContext context) throws AuthenticationException { Args.notNull(host, "Auth host"); Args.notNull(credentialsProvider, "CredentialsProvider"); final Credentials credentials = credentialsProvider.getCredentials( new AuthScope(host, getRealm(), getName()), context); if (credentials != null) { this.username = credentials.getUserPrincipal().getName(); this.password = credentials.getPassword(); return true; } this.username = null; this.password = null; return false; }
credsProvider.setCredentials(new AuthScope(proxy), credentials);