On Thu, 2014-01-09 at 00:32 +0000, Lansing, Carina S wrote:
> Will do - thanks Oleg!
> 

Carina,

Could you please try out this patch (attached)?

If you are comfortable using GitHub you can clone the patched version
from here

https://github.com/ok2c/httpclient.git

Oleg

> -----Original Message-----
> From: Oleg Kalnichevski [mailto:[email protected]] 
> Sent: Wednesday, January 08, 2014 2:20 AM
> To: HttpClient User Discussion
> Subject: Re: Proxy authentication Error - NTLM authentication error: 
> Unexpected state: MSG_TYPE3_GENERATED in Http Client 4.3.1
> 
> On Tue, 2014-01-07 at 21:28 +0000, Lansing, Carina S wrote:
> > Hi All,
> > 
> > We are using httpclient 4.3.1, trying to connect to a website that requires 
> > basic authentication through an NTLM v2 proxy.  It appears that the proxy 
> > authentication is successfully negotiated, but then when trying to process 
> > the challenge from the target web site in the next pass, the NTLMScheme is 
> > throwing this exception at line  147?  We are instantiating our http client 
> > via the snippet shown below.  Our software is a collaborative modeling & 
> > visualization tool that runs from several different external locations.  We 
> > just got a new user who sits behind an NTLM v2 proxy, so we had to upgrade 
> > our httpclient library, which required me to change how our httpclient is 
> > instantiated.  Please let me know if you see any problems.  Following the 
> > code snippet is a debug trace of the HttpGet  operation.
> > 
> > Thanks,
> > Carina
> 
> Hi Carina
> 
> Your code looks all right to me. This is likely to be a bug in HttpClient. 
> Could you please raise a JIRA for this defect?
> 
> Oleg
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 

diff --git a/httpclient/src/main/java-deprecated/org/apache/http/impl/client/DefaultRequestDirector.java b/httpclient/src/main/java-deprecated/org/apache/http/impl/client/DefaultRequestDirector.java
index 8221ff0..056d3f5 100644
--- a/httpclient/src/main/java-deprecated/org/apache/http/impl/client/DefaultRequestDirector.java
+++ b/httpclient/src/main/java-deprecated/org/apache/http/impl/client/DefaultRequestDirector.java
@@ -1026,22 +1026,26 @@ public class DefaultRequestDirector implements RequestDirector {
                 final Scheme scheme = connManager.getSchemeRegistry().getScheme(target);
                 target = new HttpHost(target.getHostName(), scheme.getDefaultPort(), target.getSchemeName());
             }
-            if (this.authenticator.isAuthenticationRequested(target, response,
-                    this.targetAuthStrategy, this.targetAuthState, context)) {
+
+            final boolean targetAuthRequested = this.authenticator.isAuthenticationRequested(
+                    target, response, this.targetAuthStrategy, targetAuthState, context);
+
+            HttpHost proxy = route.getProxyHost();
+            // if proxy is not set use target host instead
+            if (proxy == null) {
+                proxy = route.getTargetHost();
+            }
+            final boolean proxyAuthRequested = this.authenticator.isAuthenticationRequested(
+                    proxy, response, this.proxyAuthStrategy, proxyAuthState, context);
+
+            if (targetAuthRequested) {
                 if (this.authenticator.authenticate(target, response,
                         this.targetAuthStrategy, this.targetAuthState, context)) {
                     // Re-try the same request via the same route
                     return roureq;
                 }
             }
-
-            HttpHost proxy = route.getProxyHost();
-            if (this.authenticator.isAuthenticationRequested(proxy, response,
-                    this.proxyAuthStrategy, this.proxyAuthState, context)) {
-                // if proxy is not set use target host instead
-                if (proxy == null) {
-                    proxy = route.getTargetHost();
-                }
+            if (proxyAuthRequested) {
                 if (this.authenticator.authenticate(proxy, response,
                         this.proxyAuthStrategy, this.proxyAuthState, context)) {
                     // Re-try the same request via the same route
diff --git a/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java b/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
index 7c88eff..f8842f4 100644
--- a/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
+++ b/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
@@ -544,18 +544,22 @@ public class MainClientExec implements ClientExecChain {
                         route.getTargetHost().getPort(),
                         target.getSchemeName());
             }
-            if (this.authenticator.isAuthenticationRequested(target, response,
-                    this.targetAuthStrategy, targetAuthState, context)) {
+            final boolean targetAuthRequested = this.authenticator.isAuthenticationRequested(
+                    target, response, this.targetAuthStrategy, targetAuthState, context);
+
+            HttpHost proxy = route.getProxyHost();
+            // if proxy is not set use target host instead
+            if (proxy == null) {
+                proxy = route.getTargetHost();
+            }
+            final boolean proxyAuthRequested = this.authenticator.isAuthenticationRequested(
+                    proxy, response, this.proxyAuthStrategy, proxyAuthState, context);
+
+            if (targetAuthRequested) {
                 return this.authenticator.handleAuthChallenge(target, response,
                         this.targetAuthStrategy, targetAuthState, context);
             }
-            HttpHost proxy = route.getProxyHost();
-            if (this.authenticator.isAuthenticationRequested(proxy, response,
-                    this.proxyAuthStrategy, proxyAuthState, context)) {
-                // if proxy is not set use target host instead
-                if (proxy == null) {
-                    proxy = route.getTargetHost();
-                }
+            if (proxyAuthRequested) {
                 return this.authenticator.handleAuthChallenge(proxy, response,
                         this.proxyAuthStrategy, proxyAuthState, context);
             }

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to