List of usage examples for org.apache.http.auth AuthScheme getSchemeName
String getSchemeName();
From source file:org.eclipse.aether.transport.http.AuthSchemePool.java
public synchronized void put(AuthScheme authScheme) { if (authScheme == null) { return;/*from w w w .j a v a 2 s. c o m*/ } if (!authScheme.getSchemeName().equals(schemeName)) { schemeName = authScheme.getSchemeName(); authSchemes.clear(); } authSchemes.add(authScheme); }
From source file:org.elasticsearch.client.PersistentCredentialsAuthenticationStrategy.java
@Override public void authFailed(HttpHost host, AuthScheme authScheme, HttpContext context) { if (logger.isDebugEnabled()) { logger.debug("Authentication to " + host + " failed (scheme: " + authScheme.getSchemeName() + "). Preserving credentials for next request"); }/*from ww w . j av a 2 s.c o m*/ // Do nothing. // The superclass implementation of method will clear the credentials from the cache, but we don't }
From source file:com.unboundid.scim.sdk.PreemptiveAuthInterceptor.java
/** * Method to update the AuthState in order to preemptively supply the * credentials to the server.//from w ww . j a va 2 s .c o m * * @param host the HttpHost which we're authenticating to * @param authScheme the AuthScheme in use * @param authState the AuthState object from the HttpContext * @param credsProvider the CredentialsProvider which has the username and * password */ private void doPreemptiveAuth(final HttpHost host, final AuthScheme authScheme, final AuthState authState, final CredentialsProvider credsProvider) { final String schemeName = authScheme.getSchemeName(); final AuthScope authScope = new AuthScope(host, AuthScope.ANY_REALM, schemeName); final Credentials creds = credsProvider.getCredentials(authScope); if (creds != null) { if ("BASIC".equalsIgnoreCase(schemeName)) { authState.setState(AuthProtocolState.CHALLENGED); } else { authState.setState(AuthProtocolState.SUCCESS); } authState.update(authScheme, creds); } }
From source file:glaze.oauth.PreemptiveAuthorizer.java
/** * If no auth scheme has been selected for the given context, consider each * of the preferred auth schemes and select the first one for which an * AuthScheme and matching Credentials are available. *//*from ww w .j av a2s.c om*/ @SuppressWarnings("unchecked") public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); if (authState != null && authState.getAuthScheme() != null) { return; } HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); CredentialsProvider provider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER); AuthSchemeRegistry schemes = (AuthSchemeRegistry) context.getAttribute(ClientContext.AUTHSCHEME_REGISTRY); HttpParams params = request.getParams(); for (String schemeName : (Iterable<String>) params.getParameter(AuthPNames.PROXY_AUTH_PREF)) { AuthScheme scheme = schemes.getAuthScheme(schemeName, params); if (scheme != null) { AuthScope targetScope = new AuthScope(target.getHostName(), target.getPort(), scheme.getRealm(), scheme.getSchemeName()); Credentials creds = provider.getCredentials(targetScope); if (creds != null) { authState.update(scheme, creds); return; } } } }
From source file:net.oauth.client.httpclient4.PreemptiveAuthorizer.java
/** * If no auth scheme has been selected for the given context, consider each * of the preferred auth schemes and select the first one for which an * AuthScheme and matching Credentials are available. *///from ww w .ja v a2 s .co m public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); if (authState != null && authState.getAuthScheme() != null) { return; } HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); CredentialsProvider creds = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER); AuthSchemeRegistry schemes = (AuthSchemeRegistry) context.getAttribute(ClientContext.AUTHSCHEME_REGISTRY); for (Object schemeName : (Iterable) context.getAttribute(ClientContext.AUTH_SCHEME_PREF)) { AuthScheme scheme = schemes.getAuthScheme(schemeName.toString(), request.getParams()); if (scheme != null) { AuthScope targetScope = new AuthScope(target.getHostName(), target.getPort(), scheme.getRealm(), scheme.getSchemeName()); Credentials cred = creds.getCredentials(targetScope); if (cred != null) { authState.setAuthScheme(scheme); authState.setCredentials(cred); return; } } } }
From source file:com.grendelscan.commons.http.apache_overrides.client.CustomClientRequestDirector.java
private void updateAuthState(final AuthState authState, final HttpHost host, final CredentialsProvider credsProvider) { if (!authState.isValid()) { return;/* w w w . j a v a2s. co m*/ } String hostname = host.getHostName(); int port = host.getPort(); if (port < 0) { Scheme scheme = connManager.getSchemeRegistry().getScheme(host); port = scheme.getDefaultPort(); } AuthScheme authScheme = authState.getAuthScheme(); AuthScope authScope = new AuthScope(hostname, port, authScheme.getRealm(), authScheme.getSchemeName()); LOGGER.trace("Authentication scope: " + authScope); Credentials creds = authState.getCredentials(); if (creds == null) { creds = credsProvider.getCredentials(authScope); if (creds != null) { LOGGER.trace("Found credentials"); } else { LOGGER.trace("Credentials not found"); } } else { if (authScheme.isComplete()) { LOGGER.debug("Authentication failed"); creds = null; } } authState.setAuthScope(authScope); authState.setCredentials(creds); }
From source file:com.joyent.http.signature.apache.httpclient.HttpSignatureAuthenticationStrategy.java
@Override public void authSucceeded(final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Objects.requireNonNull(authhost, "Authentication host must be present"); Objects.requireNonNull(authScheme, "Authentication scheme must be present"); Objects.requireNonNull(context, "HTTP context must be present"); LOG.debug("HTTP Signature authentication succeeded"); final HttpClientContext clientContext = HttpClientContext.adapt(context); AuthCache authCache = clientContext.getAuthCache(); if (authCache == null) { authCache = new BasicAuthCache(); clientContext.setAuthCache(authCache); }/*from w w w . jav a 2 s. c om*/ if (LOG.isDebugEnabled()) { LOG.debug("Caching '" + authScheme.getSchemeName() + "' auth scheme for " + authhost); } authCache.put(authhost, authScheme); }
From source file:com.grendelscan.commons.http.apache_overrides.client.CustomClientRequestDirector.java
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); }//w ww . j av a 2s . c om 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); LOGGER.debug("Authorization challenge processed"); }
From source file:org.callimachusproject.client.HttpAuthenticator.java
private boolean handleAuthChallenge(final HttpHost host, final HttpResponse response, final AuthenticationStrategy authStrategy, final AuthState authState, final HttpContext context) { try {//from w w w . j ava 2s.c o m if (this.log.isDebugEnabled()) { this.log.debug(host.toHostString() + " requested authentication"); } final Map<String, Header> challenges = authStrategy.getChallenges(host, response, context); if (challenges.isEmpty()) { this.log.debug("Response contains no authentication challenges"); return false; } final AuthScheme authScheme = authState.getAuthScheme(); switch (authState.getState()) { case FAILURE: return false; case SUCCESS: authState.reset(); break; case CHALLENGED: case HANDSHAKE: if (authScheme == null) { this.log.debug("Auth scheme is null"); authStrategy.authFailed(host, null, context); authState.reset(); authState.setState(AuthProtocolState.FAILURE); return false; } case UNCHALLENGED: if (authScheme != null) { final String id = authScheme.getSchemeName(); final Header challenge = challenges.get(id.toLowerCase(Locale.US)); if (challenge != null) { this.log.debug("Authorization challenge processed"); authScheme.processChallenge(challenge); if (authScheme.isComplete()) { this.log.debug("Authentication failed"); authStrategy.authFailed(host, authState.getAuthScheme(), context); authState.reset(); authState.setState(AuthProtocolState.FAILURE); return false; } else { authState.setState(AuthProtocolState.HANDSHAKE); return true; } } else { authState.reset(); // Retry authentication with a different scheme } } } final Queue<AuthOption> authOptions = authStrategy.select(challenges, host, response, context); if (authOptions != null && !authOptions.isEmpty()) { if (this.log.isDebugEnabled()) { this.log.debug("Selected authentication options: " + authOptions); } authState.setState(AuthProtocolState.CHALLENGED); authState.update(authOptions); return true; } else { return false; } } catch (final MalformedChallengeException ex) { if (this.log.isWarnEnabled()) { this.log.warn("Malformed challenge: " + ex.getMessage()); } authState.reset(); return false; } }
From source file:org.robolectric.shadows.httpclient.DefaultRequestDirector.java
private void updateAuthState(final AuthState authState, final HttpHost host, final CredentialsProvider credsProvider) { if (!authState.isValid()) { return;//from w ww .java 2 s. c o m } String hostname = host.getHostName(); int port = host.getPort(); if (port < 0) { Scheme scheme = connManager.getSchemeRegistry().getScheme(host); port = scheme.getDefaultPort(); } AuthScheme authScheme = authState.getAuthScheme(); AuthScope authScope = new AuthScope(hostname, port, authScheme.getRealm(), authScheme.getSchemeName()); if (this.log.isDebugEnabled()) { this.log.debug("Authentication scope: " + authScope); } Credentials creds = authState.getCredentials(); if (creds == null) { creds = credsProvider.getCredentials(authScope); if (this.log.isDebugEnabled()) { if (creds != null) { this.log.debug("Found credentials"); } else { this.log.debug("Credentials not found"); } } } else { if (authScheme.isComplete()) { this.log.debug("Authentication failed"); creds = null; } } authState.setAuthScope(authScope); authState.setCredentials(creds); }