List<String> wwwAuthHeaders = response.headers().getAll(HttpHeaders.Names.WWW_AUTHENTICATE);
if (!wwwAuthHeaders.isEmpty()) {
future.setState(NettyResponseFuture.STATE.NEW);
Realm newRealm = null;
boolean negociate = wwwAuthHeaders.contains("Negotiate");
String ntlmAuthenticate = getNTLM(wwwAuthHeaders);
if (!wwwAuthHeaders.contains("Kerberos") && ntlmAuthenticate != null) {
// NTLM
newRealm = ntlmChallenge(ntlmAuthenticate, request, proxyServer, request.getHeaders(), realm, future, false);
// don't forget to reuse channel: NTLM authenticates a connection
future.setReuseChannel(true);
} else if (negociate) {
newRealm = kerberosChallenge(channel, wwwAuthHeaders, request, proxyServer, request.getHeaders(), realm, future, false);
// SPNEGO KERBEROS
if (newRealm == null)
return true;
else
// don't forget to reuse channel: KERBEROS authenticates a connection
future.setReuseChannel(true);
} else {
newRealm = new Realm.RealmBuilder()//
.clone(realm)//
.setScheme(realm.getAuthScheme())//
.setUri(request.getUri())//
.setMethodName(request.getMethod())//
.setUsePreemptiveAuth(true)//
.parseWWWAuthenticateHeader(wwwAuthHeaders.get(0))//
.build();
}
Realm nr = newRealm;
final Request nextRequest = new RequestBuilder(future.getRequest()).setHeaders(request.getHeaders()).setRealm(nr).build();
logger.debug("Sending authentication to {}", request.getUri());
Callback callback = new Callback(future) {
public void call() throws IOException {