List of usage examples for org.apache.commons.httpclient.auth AuthChallengeProcessor processChallenge
public AuthScheme processChallenge(AuthState paramAuthState, Map paramMap) throws MalformedChallengeException, AuthenticationException
From source file:org.archive.modules.credential.HttpAuthenticationCredential.java
@Override public boolean populate(CrawlURI curi, HttpClient http, HttpMethod method, Map<String, String> httpAuthChallenges) { boolean result = false; AuthChallengeProcessor authChallengeProcessor = new AuthChallengeProcessor(http.getParams()); try {//from ww w . j a v a 2s .c o m AuthScheme authScheme = authChallengeProcessor.processChallenge(method.getHostAuthState(), httpAuthChallenges); method.getHostAuthState().setAuthScheme(authScheme); } catch (MalformedChallengeException e) { return result; } catch (AuthenticationException e) { return result; } // Always add the credential to HttpState. Doing this because no way of // removing the credential once added AND there is a bug in the // credentials management system in that it always sets URI root to // null: it means the key used to find a credential is NOT realm + root // URI but just the realm. Unless I set it everytime, there is // possibility that as this thread progresses, it might come across a // realm already loaded but the login and password are from another // server. We'll get a failed authentication that'd be difficult to // explain. // // Have to make a UsernamePasswordCredentials. The httpclient auth code // does an instanceof down in its guts. UsernamePasswordCredentials upc = null; try { upc = new UsernamePasswordCredentials(getLogin(), getPassword()); http.getState().setCredentials( new AuthScope(curi.getUURI().getHost(), curi.getUURI().getPort(), getRealm()), upc); logger.fine("Credentials for realm " + getRealm() + " for CrawlURI " + curi.toString() + " added to request: " + result); http.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, Arrays.asList(AuthPolicy.DIGEST, AuthPolicy.BASIC)); result = true; } catch (URIException e) { logger.severe("Failed to parse host from " + curi + ": " + e.getMessage()); } return result; }