@Override public void process(HttpRequest request, HttpContext context) { AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE); if (authState.getAuthScheme() == null) { CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST); Credentials credentials = credsProvider.getCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort())); if (credentials != null) { authState.update(new BasicScheme(), credentials); } } } }
if (authState.getAuthScheme() == null) { AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth"); CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
private void processChallenges( final Map<String, Header> challenges, final AuthState authState, final AuthenticationHandler authHandler, final HttpResponse response, final HttpContext context) throws MalformedChallengeException, AuthenticationException { AuthScheme authScheme = authState.getAuthScheme(); if (authScheme == null) { // Authentication not attempted before authScheme = authHandler.selectScheme(challenges, response, context); authState.setAuthScheme(authScheme); } String id = authScheme.getSchemeName(); Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH)); if (challenge == null) { throw new AuthenticationException(id + " authorization challenge expected, but not found"); } authScheme.processChallenge(challenge); this.log.debug("Authorization challenge processed"); }
private void processChallenges( final Map<String, Header> challenges, final AuthState authState, final AuthenticationHandler authHandler, final HttpResponse response, final HttpContext context) throws MalformedChallengeException, AuthenticationException { AuthScheme authScheme = authState.getAuthScheme(); if (authScheme == null) { // Authentication not attempted before authScheme = authHandler.selectScheme(challenges, response, context); authState.setAuthScheme(authScheme); } String id = authScheme.getSchemeName(); Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH)); if (challenge == null) { throw new AuthenticationException(id + " authorization challenge expected, but not found"); } authScheme.processChallenge(challenge); this.log.debug("Authorization challenge processed"); }
private static Principal getAuthPrincipal(final AuthState authState) { AuthScheme scheme = authState.getAuthScheme(); if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) { Credentials creds = authState.getCredentials(); if (creds != null) { return creds.getUserPrincipal(); } } return null; }
AuthScheme authScheme = authState.getAuthScheme(); AuthScope authScope = new AuthScope( hostname,
AuthScheme authScheme = authState.getAuthScheme(); if (authScheme == null) { return;
AuthScheme authScheme = authState.getAuthScheme(); if (authScheme == null) { return;
AuthScheme authScheme = authState.getAuthScheme(); AuthScope authScope = new AuthScope( hostname,
AuthScheme authScheme = this.proxyAuthState.getAuthScheme(); AuthScope authScope = this.proxyAuthState.getAuthScope(); Credentials creds = this.proxyAuthState.getCredentials();
AuthScheme authScheme = proxyAuthState.getAuthScheme(); if (authScheme != null && authScheme.isConnectionBased()) { proxyAuthState.invalidate();
@Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE); if (authState.getAuthScheme() == null) { Credentials creds = new UsernamePasswordCredentials(myUsername, myPassword); authState.update(new BasicScheme(), creds); } }
/** {@inheritDoc} */ public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE); if (authState.getAuthScheme() == null) { CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(HttpClientContext.HTTP_TARGET_HOST); Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort())); if (creds == null) { throw new HttpException("No credentials given for preemptive authentication"); } authState.update(authScheme, creds); } } }
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { final AuthState authState = (AuthState) context .getAttribute(ClientContext.TARGET_AUTH_STATE); final CredentialsProvider credsProvider = (CredentialsProvider) context .getAttribute(ClientContext.CREDS_PROVIDER); final HttpHost targetHost = (HttpHost) context .getAttribute(ExecutionContext.HTTP_TARGET_HOST); // If not auth scheme has been initialized yet if (authState.getAuthScheme() == null) { AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); // Obtain credentials matching the target host Credentials creds = credsProvider.getCredentials(authScope); // If found, generate BasicScheme preemptively if (creds != null) { authState.setAuthScheme(new BasicScheme()); authState.setCredentials(creds); } } } }
httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0); (...) static class PreemptiveAuthInterceptor implements HttpRequestInterceptor { public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); // If no auth scheme avaialble yet, try to initialize it // preemptively if (authState.getAuthScheme() == null) { CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort())); if (creds == null) throw new HttpException("No credentials for preemptive authentication"); authState.setAuthScheme(new BasicScheme()); authState.setCredentials(creds); } } }
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE); if (authState.getAuthScheme() == null) { CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST); AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); Credentials creds = credsProvider.getCredentials(authScope); authState.update(new BasicScheme(), creds); } } }
public void process(HttpRequest request, HttpContext context) { AuthState authState = (AuthState) context.getAttribute( ClientContext.TARGET_AUTH_STATE); // If not auth scheme has been initialized yet if (authState.getAuthScheme() == null) { Credentials creds = new UsernamePasswordCredentials(username, password); authState.setAuthScheme(new BasicScheme()); authState.setCredentials(creds); } } }
private static Principal getAuthPrincipal(final AuthState authState) { final AuthScheme scheme = authState.getAuthScheme(); if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) { final Credentials creds = authState.getCredentials(); if (creds != null) { return creds.getUserPrincipal(); } } return null; }
private static Principal getAuthPrincipal(final AuthState authState) { final AuthScheme scheme = authState.getAuthScheme(); if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) { final Credentials creds = authState.getCredentials(); if (creds != null) { return creds.getUserPrincipal(); } } return null; }
private static Principal getAuthPrincipal(final AuthState authState) { AuthScheme scheme = authState.getAuthScheme(); if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) { Credentials creds = authState.getCredentials(); if (creds != null) { return creds.getUserPrincipal(); } } return null; }