44
44
import com .ning .http .client .ntlm .NTLMEngine ;
45
45
import com .ning .http .client .ntlm .NTLMEngineException ;
46
46
import com .ning .http .client .providers .netty .spnego .SpnegoEngine ;
47
- import com .ning .http .multipart .MultipartBody ;
48
47
import com .ning .http .multipart .MultipartRequestEntity ;
49
48
import com .ning .http .util .AsyncHttpProviderUtils ;
50
49
import com .ning .http .util .AuthenticatorUtils ;
@@ -536,7 +535,19 @@ private static HttpRequest construct(AsyncHttpClientConfig config,
536
535
}
537
536
ProxyServer proxyServer = request .getProxyServer () != null ? request .getProxyServer () : config .getProxyServer ();
538
537
Realm realm = request .getRealm () != null ? request .getRealm () : config .getRealm ();
538
+
539
539
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
+
540
551
switch (realm .getAuthScheme ()) {
541
552
case BASIC :
542
553
nettyRequest .setHeader (HttpHeaders .Names .AUTHORIZATION ,
@@ -555,7 +566,7 @@ private static HttpRequest construct(AsyncHttpClientConfig config,
555
566
case NTLM :
556
567
try {
557
568
nettyRequest .setHeader (HttpHeaders .Names .AUTHORIZATION ,
558
- ntlmEngine .generateType1Msg ("NTLM " + realm . getNtlmDomain (), realm . getNtlmHost () ));
569
+ ntlmEngine .generateType1Msg ("NTLM " + domain , authHost ));
559
570
} catch (NTLMEngineException e ) {
560
571
IOException ie = new IOException ();
561
572
ie .initCause (e );
@@ -1309,12 +1320,16 @@ private Realm ntlmChallenge(List<String> wwwAuth,
1309
1320
.build ();
1310
1321
future .getAndSetAuth (false );
1311
1322
} else {
1312
- String serverChallenge = wwwAuth .get (0 ).trim ().substring ("NTLM " .length ());
1313
- String challengeHeader = ntlmEngine .generateType3Msg (principal , password ,
1314
- ntlmDomain , ntlmHost , serverChallenge );
1315
-
1316
1323
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
+
1318
1333
Realm .RealmBuilder realmBuilder ;
1319
1334
if (realm != null ) {
1320
1335
realmBuilder = new Realm .RealmBuilder ().clone (realm );
0 commit comments