@@ -78,7 +78,7 @@ private Realm.RealmBuilder newRealmBuilder(Realm realm) {
7878 }
7979
8080 private Realm kerberosChallenge (List <String > proxyAuth , Request request , ProxyServer proxyServer ,
81- FluentCaseInsensitiveStringsMap headers , Realm realm , NettyResponseFuture <?> future ) throws NTLMEngineException {
81+ FluentCaseInsensitiveStringsMap headers , Realm realm , NettyResponseFuture <?> future , boolean proxyInd ) throws NTLMEngineException {
8282
8383 URI uri = request .getURI ();
8484 String host = request .getVirtualHost () == null ? AsyncHttpProviderUtils .getHost (uri ) : request .getVirtualHost ();
@@ -96,19 +96,23 @@ private Realm kerberosChallenge(List<String> proxyAuth, Request request, ProxySe
9696
9797 } catch (Throwable throwable ) {
9898 if (isNTLM (proxyAuth )) {
99- return ntlmChallenge (proxyAuth , request , proxyServer , headers , realm , future );
99+ return ntlmChallenge (proxyAuth , request , proxyServer , headers , realm , future , proxyInd );
100100 }
101101 channels .abort (future , throwable );
102102 return null ;
103103 }
104104 }
105105
106- private void addNTLMAuthorizationHeader (FluentCaseInsensitiveStringsMap headers , String challengeHeader ) {
107- headers .add (HttpHeaders .Names .AUTHORIZATION , "NTLM " + challengeHeader );
106+ private String authorizationHeaderName (boolean proxyInd ) {
107+ return proxyInd ? HttpHeaders .Names .PROXY_AUTHORIZATION : HttpHeaders .Names .AUTHORIZATION ;
108+ }
109+ 110+ private void addNTLMAuthorizationHeader (FluentCaseInsensitiveStringsMap headers , String challengeHeader , boolean proxyInd ) {
111+ headers .add (authorizationHeaderName (proxyInd ), "NTLM " + challengeHeader );
108112 }
109113
110114 private Realm ntlmChallenge (List <String > wwwAuth , Request request , ProxyServer proxyServer , FluentCaseInsensitiveStringsMap headers ,
111- Realm realm , NettyResponseFuture <?> future ) throws NTLMEngineException {
115+ Realm realm , NettyResponseFuture <?> future , boolean proxyInd ) throws NTLMEngineException {
112116
113117 boolean useRealm = proxyServer == null && realm != null ;
114118
@@ -121,7 +125,7 @@ private Realm ntlmChallenge(List<String> wwwAuth, Request request, ProxyServer p
121125 String challengeHeader = NTLMEngine .INSTANCE .generateType1Msg (ntlmDomain , ntlmHost );
122126
123127 URI uri = request .getURI ();
124- addNTLMAuthorizationHeader (headers , challengeHeader );
128+ addNTLMAuthorizationHeader (headers , challengeHeader , proxyInd );
125129 future .getAndSetAuth (false );
126130 return newRealmBuilder (realm )//
127131 .setScheme (realm .getAuthScheme ())//
@@ -131,7 +135,7 @@ private Realm ntlmChallenge(List<String> wwwAuth, Request request, ProxyServer p
131135 .build ();
132136
133137 } else {
134- addType3NTLMAuthorizationHeader (wwwAuth , headers , principal , password , ntlmDomain , ntlmHost );
138+ addType3NTLMAuthorizationHeader (wwwAuth , headers , principal , password , ntlmDomain , ntlmHost , proxyInd );
135139 Realm .AuthScheme authScheme = realm != null ? realm .getAuthScheme () : Realm .AuthScheme .NTLM ;
136140 return newRealmBuilder (realm )//
137141 .setScheme (authScheme )//
@@ -142,12 +146,12 @@ private Realm ntlmChallenge(List<String> wwwAuth, Request request, ProxyServer p
142146 }
143147
144148 private Realm ntlmProxyChallenge (List <String > wwwAuth , Request request , ProxyServer proxyServer ,
145- FluentCaseInsensitiveStringsMap headers , Realm realm , NettyResponseFuture <?> future ) throws NTLMEngineException {
149+ FluentCaseInsensitiveStringsMap headers , Realm realm , NettyResponseFuture <?> future , boolean proxyInd ) throws NTLMEngineException {
146150 future .getAndSetAuth (false );
147151 headers .remove (HttpHeaders .Names .PROXY_AUTHORIZATION );
148152
149153 addType3NTLMAuthorizationHeader (wwwAuth , headers , proxyServer .getPrincipal (), proxyServer .getPassword (),
150- proxyServer .getNtlmDomain (), proxyServer .getHost ());
154+ proxyServer .getNtlmDomain (), proxyServer .getHost (), proxyInd );
151155
152156 return newRealmBuilder (realm )//
153157 // .setScheme(realm.getAuthScheme())
@@ -156,13 +160,13 @@ private Realm ntlmProxyChallenge(List<String> wwwAuth, Request request, ProxySer
156160 }
157161
158162 private void addType3NTLMAuthorizationHeader (List <String > auth , FluentCaseInsensitiveStringsMap headers , String username ,
159- String password , String domain , String workstation ) throws NTLMEngineException {
160- headers .remove (HttpHeaders . Names . AUTHORIZATION );
163+ String password , String domain , String workstation , boolean proxyInd ) throws NTLMEngineException {
164+ headers .remove (authorizationHeaderName ( proxyInd ) );
161165
162166 if (isNonEmpty (auth ) && auth .get (0 ).startsWith ("NTLM " )) {
163167 String serverChallenge = auth .get (0 ).trim ().substring ("NTLM " .length ());
164168 String challengeHeader = NTLMEngine .INSTANCE .generateType3Msg (username , password , domain , workstation , serverChallenge );
165- addNTLMAuthorizationHeader (headers , challengeHeader );
169+ addNTLMAuthorizationHeader (headers , challengeHeader , proxyInd );
166170 }
167171 }
168172
@@ -236,10 +240,10 @@ private boolean handleUnauthorizedAndExit(int statusCode, Realm realm, final Req
236240 // NTLM
237241 boolean negociate = authenticateHeaders .contains ("Negotiate" );
238242 if (!authenticateHeaders .contains ("Kerberos" ) && (isNTLM (authenticateHeaders ) || negociate )) {
239- newRealm = ntlmChallenge (authenticateHeaders , request , proxyServer , request .getHeaders (), realm , future );
243+ newRealm = ntlmChallenge (authenticateHeaders , request , proxyServer , request .getHeaders (), realm , future , false );
240244 // SPNEGO KERBEROS
241245 } else if (negociate ) {
242- newRealm = kerberosChallenge (authenticateHeaders , request , proxyServer , request .getHeaders (), realm , future );
246+ newRealm = kerberosChallenge (authenticateHeaders , request , proxyServer , request .getHeaders (), realm , future , false );
243247 if (newRealm == null ) {
244248 return true ;
245249 }
@@ -305,10 +309,10 @@ private boolean handleProxyAuthenticationRequiredAndExit(int statusCode,//
305309
306310 boolean negociate = proxyAuthenticateHeaders .contains ("Negotiate" );
307311 if (!proxyAuthenticateHeaders .contains ("Kerberos" ) && (isNTLM (proxyAuthenticateHeaders ) || negociate )) {
308- newRealm = ntlmProxyChallenge (proxyAuthenticateHeaders , request , proxyServer , request .getHeaders (), realm , future );
312+ newRealm = ntlmProxyChallenge (proxyAuthenticateHeaders , request , proxyServer , request .getHeaders (), realm , future , true );
309313 // SPNEGO KERBEROS
310314 } else if (negociate ) {
311- newRealm = kerberosChallenge (proxyAuthenticateHeaders , request , proxyServer , request .getHeaders (), realm , future );
315+ newRealm = kerberosChallenge (proxyAuthenticateHeaders , request , proxyServer , request .getHeaders (), realm , future , true );
312316 if (newRealm == null )
313317 return true ;
314318 } else {
@@ -459,10 +463,12 @@ && handleResponseAndExit(channel, future, handler, nettyRequest.getHttpRequest()
459463
460464 try {
461465 channels .abort (future , t );
466+ } catch (Exception abortException ) {
467+ LOGGER .debug ("Abort failed" , abortException );
462468 } finally {
463469 finishUpdate (future , channel , false );
464- throw t ;
465470 }
471+ throw t ;
466472 }
467473 }
468474
0 commit comments