hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject httpcomponents-client git commit: HTTPCLIENT-1855: Update DIGEST nonce counter in auth cache after auth challenge
Date Tue, 03 Oct 2017 09:41:14 GMT
Repository: httpcomponents-client
Updated Branches:
  refs/heads/4.6.x 5a44282ca -> c82799f1e


HTTPCLIENT-1855: Update DIGEST nonce counter in auth cache after auth challenge


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/c82799f1
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/c82799f1
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/c82799f1

Branch: refs/heads/4.6.x
Commit: c82799f1eb29e3f74bac0c7be61c8f3e37d702e4
Parents: 5a44282
Author: alessandro.gherardi <alessandro.gherardi@schneider-electric.com>
Authored: Mon Oct 2 10:06:07 2017 -0600
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Tue Oct 3 11:36:33 2017 +0200

----------------------------------------------------------------------
 .../http/client/protocol/RequestAuthCache.java  |  4 ++-
 .../client/protocol/TestRequestAuthCache.java   | 32 ++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/c82799f1/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
----------------------------------------------------------------------
diff --git a/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
b/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
index aa30073..7bf37e6 100644
--- a/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
+++ b/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
@@ -44,6 +44,7 @@ import org.apache.http.auth.AuthState;
 import org.apache.http.auth.Credentials;
 import org.apache.http.client.AuthCache;
 import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.AuthSchemes;
 import org.apache.http.conn.routing.RouteInfo;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.Args;
@@ -135,7 +136,8 @@ public class RequestAuthCache implements HttpRequestInterceptor {
         final Credentials creds = credsProvider.getCredentials(authScope);
 
         if (creds != null) {
-            if ("BASIC".equalsIgnoreCase(authScheme.getSchemeName())) {
+            if (AuthSchemes.BASIC.equalsIgnoreCase(authScheme.getSchemeName())
+                    || AuthSchemes.DIGEST.equalsIgnoreCase(authScheme.getSchemeName())) {
                 authState.setState(AuthProtocolState.CHALLENGED);
             } else {
                 authState.setState(AuthProtocolState.SUCCESS);

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/c82799f1/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java
----------------------------------------------------------------------
diff --git a/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java
b/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java
index 6bc3d95..1c0d323 100644
--- a/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java
+++ b/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java
@@ -37,6 +37,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.AuthCache;
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.impl.auth.DigestScheme;
 import org.apache.http.impl.client.BasicAuthCache;
 import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.message.BasicHttpRequest;
@@ -55,6 +56,8 @@ public class TestRequestAuthCache {
     private AuthScope authscope2;
     private BasicScheme authscheme1;
     private BasicScheme authscheme2;
+    private DigestScheme digestAuthscheme1;
+    private DigestScheme digestAuthscheme2;
     private BasicCredentialsProvider credProvider;
     private AuthState targetState;
     private AuthState proxyState;
@@ -71,6 +74,8 @@ public class TestRequestAuthCache {
         this.authscope2 = new AuthScope(this.proxy);
         this.authscheme1 = new BasicScheme();
         this.authscheme2 = new BasicScheme();
+        this.digestAuthscheme1 = new DigestScheme();
+        this.digestAuthscheme2 = new DigestScheme();
 
         this.credProvider.setCredentials(this.authscope1, this.creds1);
         this.credProvider.setCredentials(this.authscope2, this.creds2);
@@ -119,6 +124,33 @@ public class TestRequestAuthCache {
     }
 
     @Test
+    public void testPreemptiveTargetAndProxyAuthDigest() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("GET", "/");
+
+        final HttpClientContext context = HttpClientContext.create();
+        context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credProvider);
+        context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
+        context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null,
this.proxy, false));
+        context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
+        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);
+
+        final AuthCache authCache = new BasicAuthCache();
+        authCache.put(this.target, this.digestAuthscheme1);
+        authCache.put(this.proxy, this.digestAuthscheme2);
+
+        context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
+
+        final HttpRequestInterceptor interceptor = new RequestAuthCache();
+        interceptor.process(request, context);
+        Assert.assertNotNull(this.targetState.getAuthScheme());
+        Assert.assertSame(this.targetState.getState(), AuthProtocolState.CHALLENGED);
+        Assert.assertSame(this.creds1, this.targetState.getCredentials());
+        Assert.assertNotNull(this.proxyState.getAuthScheme());
+        Assert.assertSame(this.proxyState.getState(), AuthProtocolState.CHALLENGED);
+        Assert.assertSame(this.creds2, this.proxyState.getCredentials());
+    }
+
+    @Test
     public void testCredentialsProviderNotSet() throws Exception {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
 


Mime
View raw message