public void update(AuthScheme authScheme, Credentials credentials) { Args.notNull(authScheme, "Auth scheme"); Args.notNull(credentials, "Credentials"); this.authScheme = authScheme; this.credentials = credentials; this.authOptions = null; }
public Queue<AuthOption> select( Map<String, Header> challenges, HttpHost authhost, HttpResponse response, HttpContext context) throws MalformedChallengeException { Args.notNull(challenges, "Map of auth challenges"); Args.notNull(authhost, "Host"); Args.notNull(response, "HTTP response"); Args.notNull(context, "HTTP context"); HttpClientContext clientContext = HttpClientContext.adapt(context); Queue<AuthOption> options = new LinkedList(); Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry(); if (registry == null) { this.log.debug("Auth scheme registry not set in the context"); return options; } CredentialsProvider credsProvider = clientContext.getCredentialsProvider(); if (credsProvider == null) { this.log.debug("Credentials provider not set in the context"); return options; } RequestConfig config = clientContext.getRequestConfig(); Collection<String> authPrefs = getPreferredAuthSchemes(config); if (authPrefs == null) { authPrefs = DEFAULT_SCHEME_PRIORITY; } if (this.log.isDebugEnabled()) { this.log.debug("Authentication schemes in the order of preference: " + authPrefs); } for (String id : authPrefs) { Header challenge = (Header) challenges.get(id.toLowerCase(Locale.US)); if (challenge != null) { AuthSchemeProvider authSchemeProvider = (AuthSchemeProvider) registry.lookup(id); if (authSchemeProvider == null) { if (this.log.isWarnEnabled()) { this.log.warn("Authentication scheme " + id + " not supported"); } } else { AuthScheme authScheme = authSchemeProvider.create(context); authScheme.processChallenge(challenge); AuthScope authScope = new AuthScope( authhost.getHostName(), authhost.getPort(), authScheme.getRealm(), authScheme.getSchemeName()); Credentials credentials = credsProvider.getCredentials(authScope); if (credentials != null) { options.add(new AuthOption(authScheme, credentials)); } } } else if (this.log.isDebugEnabled()) { this.log.debug("Challenge for " + id + " authentication scheme not available"); } } return options; }
public void authFailed(HttpHost authhost, AuthScheme authScheme, HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(context, "HTTP context"); HttpClientContext clientContext = HttpClientContext.adapt(context); AuthCache authCache = clientContext.getAuthCache(); if (authCache != null) { if (this.log.isDebugEnabled()) { this.log.debug("Clearing cached auth scheme for " + authhost); } authCache.remove(authhost); } }
public Map<String, Header> getChallenges( HttpHost authhost, HttpResponse response, HttpContext context) throws MalformedChallengeException { Args.notNull(response, "HTTP response"); Header[] headers = response.getHeaders(this.headerName); Map<String, Header> map = new HashMap(headers.length); for (Header header : headers) { int pos; CharArrayBuffer buffer; int pos; if ((header instanceof FormattedHeader)) { CharArrayBuffer buffer = ((FormattedHeader) header).getBuffer(); pos = ((FormattedHeader) header).getValuePos(); } else { String s = header.getValue(); if (s == null) { throw new MalformedChallengeException("Header value is null"); } buffer = new CharArrayBuffer(s.length()); buffer.append(s); pos = 0; } while ((pos < buffer.length()) && (HTTP.isWhitespace(buffer.charAt(pos)))) { pos++; } int beginIndex = pos; while ((pos < buffer.length()) && (!HTTP.isWhitespace(buffer.charAt(pos)))) { pos++; } int endIndex = pos; String s = buffer.substring(beginIndex, endIndex); map.put(s.toLowerCase(Locale.US), header); } return map; }
public SerializableEntity(Serializable ser, boolean bufferize) throws IOException { Args.notNull(ser, "Source object"); if (bufferize) { createBytes(ser); } else { this.objRef = ser; } }
public void authSucceeded(HttpHost authhost, AuthScheme authScheme, HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(authScheme, "Auth scheme"); Args.notNull(context, "HTTP context"); HttpClientContext clientContext = HttpClientContext.adapt(context); if (isCachable(authScheme)) { AuthCache authCache = clientContext.getAuthCache(); if (authCache == null) { authCache = new BasicAuthCache(); clientContext.setAuthCache(authCache); } if (this.log.isDebugEnabled()) { this.log.debug("Caching '" + authScheme.getSchemeName() + "' auth scheme for " + authhost); } authCache.put(authhost, authScheme); } }
public void writeTo(OutputStream outstream) throws IOException { Args.notNull(outstream, "Output stream"); if (this.objSer == null) { ObjectOutputStream out = new ObjectOutputStream(outstream); out.writeObject(this.objRef); out.flush(); } else { outstream.write(this.objSer); outstream.flush(); } }
public void update(Queue<AuthOption> authOptions) { Args.notEmpty(authOptions, "Queue of auth options"); this.authOptions = authOptions; this.authScheme = null; this.credentials = null; }
public DefaultProxyRoutePlanner(HttpHost proxy, SchemePortResolver schemePortResolver) { super(schemePortResolver); this.proxy = ((HttpHost) Args.notNull(proxy, "Proxy host")); }
public boolean isAuthenticationRequested( HttpHost authhost, HttpResponse response, HttpContext context) { Args.notNull(response, "HTTP response"); int status = response.getStatusLine().getStatusCode(); return status == this.challengeCode; }
public String getParameter(String name) { Args.notNull(name, "Parameter name"); return null; }
public SerializableEntity(Serializable ser) { Args.notNull(ser, "Source object"); this.objRef = ser; }