List of usage examples for org.apache.http.impl.client TargetAuthenticationStrategy INSTANCE
TargetAuthenticationStrategy INSTANCE
To view the source code for org.apache.http.impl.client TargetAuthenticationStrategy INSTANCE.
Click Source Link
From source file:org.archive.modules.fetcher.FetchHTTP.java
/** * Server is looking for basic/digest auth credentials (RFC2617). If we have * any, put them into the CrawlURI and have it come around again. * Presence of the credential serves as flag to frontier to requeue * promptly. If we already tried this domain and still got a 401, then our * credentials are bad. Remove them and let this curi die. * @param httpClient // w w w. j a v a2 s. c om * @param response 401 http response * @param curi * CrawlURI that got a 401. */ protected void handle401(HttpResponse response, final CrawlURI curi) { Map<String, String> challenges = extractChallenges(response, curi, TargetAuthenticationStrategy.INSTANCE); AuthScheme authscheme = chooseAuthScheme(challenges, HttpHeaders.WWW_AUTHENTICATE); // remember WWW-Authenticate headers for later use curi.setHttpAuthChallenges(challenges); if (authscheme == null) { return; } String realm = authscheme.getRealm(); // Look to see if this curi had rfc2617 avatars loaded. If so, are // any of them for this realm? If so, then the credential failed // if we got a 401 and it should be let die a natural 401 death. Set<Credential> curiRfc2617Credentials = getCredentials(curi, HttpAuthenticationCredential.class); HttpAuthenticationCredential extant = HttpAuthenticationCredential.getByRealm(curiRfc2617Credentials, realm, curi); if (extant != null) { // Then, already tried this credential. Remove ANY rfc2617 // credential since presence of a rfc2617 credential serves // as flag to frontier to requeue this curi and let the curi // die a natural death. extant.detachAll(curi); logger.warning("Auth failed (401) though supplied realm " + realm + " to " + curi.toString()); } else { // Look see if we have a credential that corresponds to this // realm in credential store. Filter by type and credential // domain. If not, let this curi die. Else, add it to the // curi and let it come around again. Add in the AuthScheme // we got too. Its needed when we go to run the Auth on // second time around. String serverKey = getServerKey(curi); CrawlServer server = serverCache.getServerFor(serverKey); Set<Credential> storeRfc2617Credentials = getCredentialStore().subset(curi, HttpAuthenticationCredential.class, server.getName()); if (storeRfc2617Credentials == null || storeRfc2617Credentials.size() <= 0) { logger.fine("No rfc2617 credentials for " + curi); } else { HttpAuthenticationCredential found = HttpAuthenticationCredential .getByRealm(storeRfc2617Credentials, realm, curi); if (found == null) { logger.fine("No rfc2617 credentials for realm " + realm + " in " + curi); } else { found.attach(curi); logger.fine("Found credential for scheme " + authscheme + " realm " + realm + " in store for " + curi.toString()); } } } }