Skip to content

Commit 1b92fd3

Browse files
committed
More work on AHC-79: use the proxy information after auth challenge
1 parent 8c663d9 commit 1b92fd3

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import com.ning.http.client.ntlm.NTLMEngine;
4545
import com.ning.http.client.ntlm.NTLMEngineException;
4646
import com.ning.http.client.providers.netty.spnego.SpnegoEngine;
47-
import com.ning.http.multipart.MultipartBody;
4847
import com.ning.http.multipart.MultipartRequestEntity;
4948
import com.ning.http.util.AsyncHttpProviderUtils;
5049
import com.ning.http.util.AuthenticatorUtils;
@@ -536,7 +535,19 @@ private static HttpRequest construct(AsyncHttpClientConfig config,
536535
}
537536
ProxyServer proxyServer = request.getProxyServer() != null ? request.getProxyServer() : config.getProxyServer();
538537
Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm();
538+
539539
if (realm != null && realm.getUsePreemptiveAuth()) {
540+
541+
String domain = realm.getNtlmDomain();
542+
if (proxyServer != null && proxyServer.getNtlmDomain() != null) {
543+
domain = proxyServer.getNtlmDomain();
544+
}
545+
546+
String authHost = realm.getNtlmHost();
547+
if (proxyServer != null && proxyServer.getHost() != null) {
548+
host = proxyServer.getHost();
549+
}
550+
540551
switch (realm.getAuthScheme()) {
541552
case BASIC:
542553
nettyRequest.setHeader(HttpHeaders.Names.AUTHORIZATION,
@@ -555,7 +566,7 @@ private static HttpRequest construct(AsyncHttpClientConfig config,
555566
case NTLM:
556567
try {
557568
nettyRequest.setHeader(HttpHeaders.Names.AUTHORIZATION,
558-
ntlmEngine.generateType1Msg("NTLM " + realm.getNtlmDomain(), realm.getNtlmHost()));
569+
ntlmEngine.generateType1Msg("NTLM " + domain, authHost));
559570
} catch (NTLMEngineException e) {
560571
IOException ie = new IOException();
561572
ie.initCause(e);
@@ -1309,12 +1320,16 @@ private Realm ntlmChallenge(List<String> wwwAuth,
13091320
.build();
13101321
future.getAndSetAuth(false);
13111322
} else {
1312-
String serverChallenge = wwwAuth.get(0).trim().substring("NTLM ".length());
1313-
String challengeHeader = ntlmEngine.generateType3Msg(principal, password,
1314-
ntlmDomain, ntlmHost, serverChallenge);
1315-
13161323
headers.remove(HttpHeaders.Names.AUTHORIZATION);
1317-
headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader);
1324+
1325+
if (wwwAuth.get(0).startsWith("NTLM ")) {
1326+
String serverChallenge = wwwAuth.get(0).trim().substring("NTLM ".length());
1327+
String challengeHeader = ntlmEngine.generateType3Msg(principal, password,
1328+
ntlmDomain, ntlmHost, serverChallenge);
1329+
1330+
headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader);
1331+
}
1332+
13181333
Realm.RealmBuilder realmBuilder;
13191334
if (realm != null) {
13201335
realmBuilder = new Realm.RealmBuilder().clone(realm);

0 commit comments

Comments
 (0)