From f4ef817d255ecb471b4a6c5aed66dfd87329f355 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Wed, 9 Feb 2011 13:42:33 +0000 Subject: [PATCH] HTTPCLIENT-1056: Fixed bug causing the RequestAuthCache protocol interceptor to generate an invalid AuthScope instance when looking up user credentials for preemptive authentication git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1068881 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE_NOTES.txt | 4 ++++ .../main/java/org/apache/http/auth/AuthScope.java | 15 +++++++++++++++ .../http/client/protocol/RequestAuthCache.java | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index e02d1a968..38eca1dd1 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,5 +1,9 @@ Changes since 4.1 +* [HTTPCLIENT-1056] Fixed bug causing the RequestAuthCache protocol interceptor to generate + an invalid AuthScope instance when looking up user credentials for preemptive authentication. + Contributed by Oleg Kalnichevski + * [HTTPCLIENT-1053] Fixed the way DigestScheme generates nonce-count values. Contributed by Oleg Kalnichevski diff --git a/httpclient/src/main/java/org/apache/http/auth/AuthScope.java b/httpclient/src/main/java/org/apache/http/auth/AuthScope.java index f14627cff..26e6f7040 100644 --- a/httpclient/src/main/java/org/apache/http/auth/AuthScope.java +++ b/httpclient/src/main/java/org/apache/http/auth/AuthScope.java @@ -28,6 +28,7 @@ package org.apache.http.auth; import java.util.Locale; +import org.apache.http.HttpHost; import org.apache.http.annotation.Immutable; import org.apache.http.util.LangUtils; @@ -109,6 +110,20 @@ public class AuthScope { this.scheme = (scheme == null) ? ANY_SCHEME: scheme.toUpperCase(Locale.ENGLISH); } + /** + * @since 4.2 + */ + public AuthScope(final HttpHost host, final String realm, final String schemeName) { + this(host.getHostName(), host.getPort(), realm, schemeName); + } + + /** + * @since 4.2 + */ + public AuthScope(final HttpHost host) { + this(host, ANY_REALM, ANY_SCHEME); + } + /** Creates a new credentials scope for the given * host, port, realm, and any * authentication scheme. 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 efc8d854c..39af378d9 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 @@ -116,7 +116,7 @@ public class RequestAuthCache implements HttpRequestInterceptor { } Credentials creds = credsProvider.getCredentials( - new AuthScope(host.getHostName(), host.getPort(), schemeName)); + new AuthScope(host, AuthScope.ANY_REALM, schemeName)); if (creds != null) { authState.setAuthScheme(authScheme);