break;
}
boolean authenticated = false;
// if there was a header requesting authentication
if (challenges.length > 0) {
AuthScheme authscheme = null;
try {
authscheme = HttpAuthenticator.selectAuthScheme(challenges);
} catch (MalformedChallengeException e) {
if (LOG.isErrorEnabled()) {
LOG.error(e.getMessage(), e);
}
return true;
} catch (UnsupportedOperationException e) {
if (LOG.isErrorEnabled()) {
LOG.error(e.getMessage(), e);
}
return true;
}
StringBuffer buffer = new StringBuffer();
buffer.append(conn.getHost());
int port = conn.getPort();
if (conn.getProtocol().getDefaultPort() != port) {
buffer.append(':');
buffer.append(port);
}
buffer.append('#');
buffer.append(authscheme.getID());
String realm = buffer.toString();
if (realmsUsed.contains(realm)) {
if (LOG.isInfoEnabled()) {
LOG.info("Already tried to authenticate to \""
+ realm + "\" but still receiving "
+ statusCode + ".");
}
return true;
} else {
realmsUsed.add(realm);
}
try {
//remove preemptive header and reauthenticate
switch (statusCode) {
case HttpStatus.SC_UNAUTHORIZED:
removeRequestHeader(HttpAuthenticator.WWW_AUTH_RESP);
authenticated = HttpAuthenticator.authenticate(
authscheme, this, conn, state);
this.realm = authscheme.getRealm();
break;
case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
removeRequestHeader(HttpAuthenticator.PROXY_AUTH_RESP);
authenticated = HttpAuthenticator.authenticateProxy(
authscheme, this, conn, state);
this.proxyRealm = authscheme.getRealm();
break;
}
} catch (AuthenticationException e) {
LOG.warn(e.getMessage());
return true; // finished request