hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1376852 - in /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client: DefaultRequestDirector.java HttpAuthenticator.java
Date Fri, 24 Aug 2012 08:05:44 GMT
Author: olegk
Date: Fri Aug 24 08:05:44 2012
New Revision: 1376852

URL: http://svn.apache.org/viewvc?rev=1376852&view=rev
Log:
HTTPCLIENT-1224: (regression) NTLM auth not retried after a redirect over a non-persistent
connection (merged from 4.2.x branch)

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=1376852&r1=1376851&r2=1376852&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Fri Aug 24 08:05:44 2012
@@ -555,13 +555,13 @@ public class DefaultRequestDirector impl
                         managedConn.markReusable();
                     } else {
                         managedConn.close();
-                        if (proxyAuthState.getState() == AuthProtocolState.SUCCESS
+                        if (proxyAuthState.getState().compareTo(AuthProtocolState.CHALLENGED)
> 0
                                 && proxyAuthState.getAuthScheme() != null
                                 && proxyAuthState.getAuthScheme().isConnectionBased())
{
                             this.log.debug("Resetting proxy auth state");
                             proxyAuthState.reset();
                         }
-                        if (targetAuthState.getState() == AuthProtocolState.SUCCESS
+                        if (targetAuthState.getState().compareTo(AuthProtocolState.CHALLENGED)
> 0
                                 && targetAuthState.getAuthScheme() != null
                                 && targetAuthState.getAuthScheme().isConnectionBased())
{
                             this.log.debug("Resetting target auth state");
@@ -1053,6 +1053,36 @@ public class DefaultRequestDirector impl
         RequestWrapper request = roureq.getRequest();
 
         HttpParams params = request.getParams();
+
+        if (HttpClientParams.isAuthenticating(params)) {
+            HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
+            if (target == null) {
+                target = route.getTargetHost();
+            }
+            if (target.getPort() < 0) {
+                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)) {
+                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 (this.authenticator.authenticate(proxy, response,
+                        this.proxyAuthStrategy, this.proxyAuthState, context)) {
+                    // Re-try the same request via the same route
+                    return roureq;
+                }
+            }
+        }
+        
         if (HttpClientParams.isRedirecting(params) &&
                 this.redirectStrategy.isRedirected(request, response, context)) {
 
@@ -1103,38 +1133,6 @@ public class DefaultRequestDirector impl
             return newRequest;
         }
 
-        if (HttpClientParams.isAuthenticating(params)) {
-            HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
-            if (target == null) {
-                target = route.getTargetHost();
-            }
-            if (target.getPort() < 0) {
-                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)) {
-                if (this.authenticator.authenticate(target, response,
-                        this.targetAuthStrategy, this.targetAuthState, context)) {
-                    // Re-try the same request via the same route
-                    return roureq;
-                } else {
-                    return null;
-                }
-            }
-
-            HttpHost proxy = route.getProxyHost();
-            if (this.authenticator.isAuthenticationRequested(proxy, response,
-                    this.proxyAuthStrategy, this.proxyAuthState, context)) {
-                if (this.authenticator.authenticate(proxy, response,
-                        this.proxyAuthStrategy, this.proxyAuthState, context)) {
-                    // Re-try the same request via the same route
-                    return roureq;
-                } else {
-                    return null;
-                }
-            }
-        }
         return null;
     } // handleResponse
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java?rev=1376852&r1=1376851&r2=1376852&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpAuthenticator.java
Fri Aug 24 08:05:44 2012
@@ -70,11 +70,13 @@ public class HttpAuthenticator {
             final AuthState authState,
             final HttpContext context) {
         if (authStrategy.isAuthenticationRequested(host, response, context)) {
+            this.log.debug("Authentication required");
             return true;
         } else {
             switch (authState.getState()) {
             case CHALLENGED:
             case HANDSHAKE:
+                this.log.debug("Authentication succeeded");
                 authState.setState(AuthProtocolState.SUCCESS);
                 authStrategy.authSucceeded(host, authState.getAuthScheme(), context);
                 break;



Mime
View raw message