From fb56b49465e9c58d00343df56ef3a7b01ec90513 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sat, 27 Jun 2015 10:50:38 +0000 Subject: [PATCH] Redesign of CredentialsProvider interface git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1687908 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/http/client/fluent/Executor.java | 22 ++++----- .../osgi/impl/OSGiCredentialsProvider.java | 4 +- .../auth/win/WindowsCredentialsProvider.java | 10 ++-- .../http/impl/client/WinHttpClients.java | 2 +- .../auth/win/TestWindowsNegotiateScheme.java | 11 +++-- .../examples/client/ClientAuthentication.java | 3 +- .../examples/client/ClientConfiguration.java | 2 +- .../ClientPreemptiveBasicAuthentication.java | 3 +- .../ClientPreemptiveDigestAuthentication.java | 3 +- .../client/ClientProxyAuthentication.java | 3 +- .../apache/http/auth/CredentialsProvider.java | 49 +++++++++++++++++++ ...alsProvider.java => CredentialsStore.java} | 16 ++---- .../client/protocol/HttpClientContext.java | 4 +- .../client/protocol/RequestAuthCache.java | 2 +- .../client/AuthenticationStrategyImpl.java | 2 +- .../impl/client/BasicCredentialsProvider.java | 6 +-- .../http/impl/client/HttpClientBuilder.java | 2 +- .../http/impl/client/InternalHttpClient.java | 2 +- .../SystemDefaultCredentialsProvider.java | 6 +-- .../http/impl/execchain/ProtocolExec.java | 16 +++--- .../client/TestAuthenticationStrategy.java | 8 +-- .../impl/client/TestInternalHttpClient.java | 2 +- .../integration/TestClientAuthentication.java | 10 +--- .../TestClientAuthenticationFallBack.java | 10 +--- .../TestClientReauthentication.java | 14 +----- .../client/integration/TestSPNegoScheme.java | 5 +- .../http/impl/execchain/TestProtocolExec.java | 5 +- 27 files changed, 114 insertions(+), 108 deletions(-) create mode 100644 httpclient/src/main/java/org/apache/http/auth/CredentialsProvider.java rename httpclient/src/main/java/org/apache/http/client/{CredentialsProvider.java => CredentialsStore.java} (82%) diff --git a/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java b/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java index 9b92fbd5a..6ef7e75cd 100644 --- a/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java +++ b/fluent-hc/src/main/java/org/apache/http/client/fluent/Executor.java @@ -43,7 +43,7 @@ import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.AuthCache; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.CookieStore; -import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.CredentialsStore; import org.apache.http.client.HttpClient; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.config.Registry; @@ -110,7 +110,7 @@ public class Executor { private final HttpClient httpclient; private volatile AuthCache authCache; - private volatile CredentialsProvider credentialsProvider; + private volatile CredentialsStore credentialsStore; private volatile CookieStore cookieStore; Executor(final HttpClient httpclient) { @@ -122,16 +122,16 @@ public class Executor { /** * @since 4.5 */ - public Executor use(final CredentialsProvider credentialsProvider) { - this.credentialsProvider = credentialsProvider; + public Executor use(final CredentialsStore credentialsStore) { + this.credentialsStore = credentialsStore; return this; } public Executor auth(final AuthScope authScope, final Credentials creds) { - if (this.credentialsProvider == null) { - this.credentialsProvider = new BasicCredentialsProvider(); + if (this.credentialsStore == null) { + this.credentialsStore = new BasicCredentialsProvider(); } - this.credentialsProvider.setCredentials(authScope, creds); + this.credentialsStore.setCredentials(authScope, creds); return this; } @@ -207,8 +207,8 @@ public class Executor { } public Executor clearAuth() { - if (this.credentialsProvider != null) { - this.credentialsProvider.clear(); + if (this.credentialsStore != null) { + this.credentialsStore.clear(); } return this; } @@ -248,8 +248,8 @@ public class Executor { public Response execute( final Request request) throws ClientProtocolException, IOException { final HttpClientContext localContext = HttpClientContext.create(); - if (this.credentialsProvider != null) { - localContext.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider); + if (this.credentialsStore != null) { + localContext.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsStore); } if (this.authCache != null) { localContext.setAttribute(HttpClientContext.AUTH_CACHE, this.authCache); diff --git a/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCredentialsProvider.java b/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCredentialsProvider.java index f2af64011..a18dacd8e 100644 --- a/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCredentialsProvider.java +++ b/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCredentialsProvider.java @@ -31,7 +31,7 @@ import java.util.Map; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.CredentialsStore; import org.apache.http.osgi.services.ProxyConfiguration; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; @@ -39,7 +39,7 @@ import org.osgi.framework.ServiceRegistration; /** * @since 4.3 */ -final class OSGiCredentialsProvider implements CredentialsProvider { +final class OSGiCredentialsProvider implements CredentialsStore { private final BundleContext bundleContext; diff --git a/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsCredentialsProvider.java b/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsCredentialsProvider.java index aae9e229f..26d554baf 100644 --- a/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsCredentialsProvider.java +++ b/httpclient-win/src/main/java/org/apache/http/impl/auth/win/WindowsCredentialsProvider.java @@ -29,12 +29,12 @@ package org.apache.http.impl.auth.win; import org.apache.http.annotation.ThreadSafe; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; -import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.CredentialsStore; import org.apache.http.client.config.AuthSchemes; import org.apache.http.util.Args; /** - * {@link org.apache.http.client.CredentialsProvider} implementation that always returns + * {@link CredentialsStore} implementation that always returns * {@link org.apache.http.impl.auth.win.CurrentWindowsCredentials} instance to NTLM * and SPNego authentication challenges. *

@@ -44,11 +44,11 @@ import org.apache.http.util.Args; * @since 4.4 */ @ThreadSafe -public class WindowsCredentialsProvider implements CredentialsProvider { +public class WindowsCredentialsProvider implements CredentialsStore { - private final CredentialsProvider provider; + private final CredentialsStore provider; - public WindowsCredentialsProvider(final CredentialsProvider provider) { + public WindowsCredentialsProvider(final CredentialsStore provider) { this.provider = Args.notNull(provider, "Credentials provider"); } diff --git a/httpclient-win/src/main/java/org/apache/http/impl/client/WinHttpClients.java b/httpclient-win/src/main/java/org/apache/http/impl/client/WinHttpClients.java index 8b81fc512..905809a54 100644 --- a/httpclient-win/src/main/java/org/apache/http/impl/client/WinHttpClients.java +++ b/httpclient-win/src/main/java/org/apache/http/impl/client/WinHttpClients.java @@ -29,7 +29,7 @@ package org.apache.http.impl.client; import java.util.Locale; import org.apache.http.auth.AuthSchemeProvider; -import org.apache.http.client.CredentialsProvider; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.client.config.AuthSchemes; import org.apache.http.config.Registry; import org.apache.http.config.RegistryBuilder; diff --git a/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java b/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java index 287fa4c89..f3b3f932e 100644 --- a/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java +++ b/httpclient-win/src/test/java/org/apache/http/impl/auth/win/TestWindowsNegotiateScheme.java @@ -28,10 +28,6 @@ package org.apache.http.impl.auth.win; import java.io.IOException; -import com.sun.jna.platform.win32.Sspi.CtxtHandle; -import com.sun.jna.platform.win32.Sspi.SecBufferDesc; -import com.sun.jna.platform.win32.Win32Exception; -import com.sun.jna.platform.win32.WinError; import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; @@ -40,7 +36,7 @@ import org.apache.http.HttpStatus; import org.apache.http.auth.AUTH; import org.apache.http.auth.AuthScheme; import org.apache.http.auth.AuthSchemeProvider; -import org.apache.http.client.CredentialsProvider; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.client.config.AuthSchemes; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -59,6 +55,11 @@ import org.junit.Assume; import org.junit.Before; import org.junit.Test; +import com.sun.jna.platform.win32.Sspi.CtxtHandle; +import com.sun.jna.platform.win32.Sspi.SecBufferDesc; +import com.sun.jna.platform.win32.Win32Exception; +import com.sun.jna.platform.win32.WinError; + /** * Unit tests for Windows negotiate authentication. */ diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientAuthentication.java b/httpclient/src/examples/org/apache/http/examples/client/ClientAuthentication.java index 5b43cb276..235d49b2f 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientAuthentication.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientAuthentication.java @@ -28,7 +28,6 @@ package org.apache.http.examples.client; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.BasicCredentialsProvider; @@ -43,7 +42,7 @@ import org.apache.http.util.EntityUtils; public class ClientAuthentication { public static void main(String[] args) throws Exception { - CredentialsProvider credsProvider = new BasicCredentialsProvider(); + BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope("localhost", 443), new UsernamePasswordCredentials("username", "password")); diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java b/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java index 932882e9c..28d18bb6f 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java @@ -41,8 +41,8 @@ import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; import org.apache.http.ParseException; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.client.CookieStore; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.AuthSchemes; import org.apache.http.client.config.CookieSpecs; import org.apache.http.client.config.RequestConfig; diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java b/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java index f2a3cec3b..f3be16672 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java @@ -30,7 +30,6 @@ import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.AuthCache; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.protocol.HttpClientContext; @@ -53,7 +52,7 @@ public class ClientPreemptiveBasicAuthentication { public static void main(String[] args) throws Exception { HttpHost target = new HttpHost("localhost", 80, "http"); - CredentialsProvider credsProvider = new BasicCredentialsProvider(); + BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials("username", "password")); diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java b/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java index d68dbb437..cb9579c66 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java @@ -30,7 +30,6 @@ import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.AuthCache; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.protocol.HttpClientContext; @@ -54,7 +53,7 @@ public class ClientPreemptiveDigestAuthentication { public static void main(String[] args) throws Exception { HttpHost target = new HttpHost("localhost", 80, "http"); - CredentialsProvider credsProvider = new BasicCredentialsProvider(); + BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials("username", "password")); diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java b/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java index e8b8336a2..846b36e1b 100644 --- a/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java +++ b/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java @@ -29,7 +29,6 @@ package org.apache.http.examples.client; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -45,7 +44,7 @@ import org.apache.http.util.EntityUtils; public class ClientProxyAuthentication { public static void main(String[] args) throws Exception { - CredentialsProvider credsProvider = new BasicCredentialsProvider(); + BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope("localhost", 8080), new UsernamePasswordCredentials("username", "password")); diff --git a/httpclient/src/main/java/org/apache/http/auth/CredentialsProvider.java b/httpclient/src/main/java/org/apache/http/auth/CredentialsProvider.java new file mode 100644 index 000000000..550c2ac40 --- /dev/null +++ b/httpclient/src/main/java/org/apache/http/auth/CredentialsProvider.java @@ -0,0 +1,49 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ +package org.apache.http.auth; + +/** + * Provider of authentication credentials. + *

+ * Implementations of this interface must be thread-safe. Access to shared + * data must be synchronized as methods of this interface may be executed + * from multiple threads. + * + * @since 4.0 + */ +public interface CredentialsProvider { + + /** + * Returns {@link Credentials credentials} for the given authentication scope, + * if available. + * + * @param authscope the {@link AuthScope authentication scope} + * @return the credentials + */ + Credentials getCredentials(AuthScope authscope); + +} diff --git a/httpclient/src/main/java/org/apache/http/client/CredentialsProvider.java b/httpclient/src/main/java/org/apache/http/client/CredentialsStore.java similarity index 82% rename from httpclient/src/main/java/org/apache/http/client/CredentialsProvider.java rename to httpclient/src/main/java/org/apache/http/client/CredentialsStore.java index cb39d3f52..2fe570861 100644 --- a/httpclient/src/main/java/org/apache/http/client/CredentialsProvider.java +++ b/httpclient/src/main/java/org/apache/http/client/CredentialsStore.java @@ -28,10 +28,10 @@ package org.apache.http.client; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; +import org.apache.http.auth.CredentialsProvider; /** - * Abstract credentials provider that maintains a collection of user - * credentials. + * Abstract store of authentication credentials. *

* Implementations of this interface must be thread-safe. Access to shared * data must be synchronized as methods of this interface may be executed @@ -39,7 +39,7 @@ import org.apache.http.auth.Credentials; * * @since 4.0 */ -public interface CredentialsProvider { +public interface CredentialsStore extends CredentialsProvider { /** * Sets the {@link Credentials credentials} for the given authentication @@ -53,16 +53,6 @@ public interface CredentialsProvider { */ void setCredentials(AuthScope authscope, Credentials credentials); - /** - * Get the {@link Credentials credentials} for the given authentication scope. - * - * @param authscope the {@link AuthScope authentication scope} - * @return the credentials - * - * @see #setCredentials(AuthScope, Credentials) - */ - Credentials getCredentials(AuthScope authscope); - /** * Clears all credentials. */ diff --git a/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java b/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java index db363c492..deba69097 100644 --- a/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java +++ b/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java @@ -33,9 +33,9 @@ import java.util.List; import org.apache.http.annotation.NotThreadSafe; import org.apache.http.auth.AuthSchemeProvider; import org.apache.http.auth.AuthState; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.client.AuthCache; import org.apache.http.client.CookieStore; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.RequestConfig; import org.apache.http.config.Lookup; import org.apache.http.conn.routing.HttpRoute; @@ -94,7 +94,7 @@ public class HttpClientContext extends HttpCoreContext { public static final String COOKIE_STORE = "http.cookie-store"; /** - * Attribute name of a {@link org.apache.http.client.CredentialsProvider} + * Attribute name of a {@link CredentialsProvider} * object that represents the actual credentials provider. */ public static final String CREDS_PROVIDER = "http.auth.credentials-provider"; 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 fa6a36299..c33eade04 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 @@ -41,8 +41,8 @@ import org.apache.http.auth.AuthScheme; import org.apache.http.auth.AuthScope; import org.apache.http.auth.AuthState; import org.apache.http.auth.Credentials; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.client.AuthCache; -import org.apache.http.client.CredentialsProvider; import org.apache.http.conn.routing.RouteInfo; import org.apache.http.protocol.HttpContext; import org.apache.http.util.Args; diff --git a/httpclient/src/main/java/org/apache/http/impl/client/AuthenticationStrategyImpl.java b/httpclient/src/main/java/org/apache/http/impl/client/AuthenticationStrategyImpl.java index 25f99f0e8..a6a65b5c9 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/AuthenticationStrategyImpl.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/AuthenticationStrategyImpl.java @@ -49,10 +49,10 @@ import org.apache.http.auth.AuthScheme; import org.apache.http.auth.AuthSchemeProvider; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.auth.MalformedChallengeException; import org.apache.http.client.AuthCache; import org.apache.http.client.AuthenticationStrategy; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.AuthSchemes; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.protocol.HttpClientContext; diff --git a/httpclient/src/main/java/org/apache/http/impl/client/BasicCredentialsProvider.java b/httpclient/src/main/java/org/apache/http/impl/client/BasicCredentialsProvider.java index d93eb7459..a2e0d4d2a 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/BasicCredentialsProvider.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/BasicCredentialsProvider.java @@ -32,16 +32,16 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.http.annotation.ThreadSafe; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; -import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.CredentialsStore; import org.apache.http.util.Args; /** - * Default implementation of {@link CredentialsProvider}. + * Default implementation of {@link CredentialsStore}. * * @since 4.0 */ @ThreadSafe -public class BasicCredentialsProvider implements CredentialsProvider { +public class BasicCredentialsProvider implements CredentialsStore { private final ConcurrentHashMap credMap; diff --git a/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java b/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java index 08e84d284..9b59a4f6b 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java @@ -49,11 +49,11 @@ import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponseInterceptor; import org.apache.http.annotation.NotThreadSafe; import org.apache.http.auth.AuthSchemeProvider; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.client.AuthenticationStrategy; import org.apache.http.client.BackoffManager; import org.apache.http.client.ConnectionBackoffStrategy; import org.apache.http.client.CookieStore; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.HttpRequestRetryHandler; import org.apache.http.client.RedirectStrategy; import org.apache.http.client.ServiceUnavailableRetryStrategy; diff --git a/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java b/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java index cbbd5acf4..72226d8b3 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java @@ -39,9 +39,9 @@ import org.apache.http.HttpRequest; import org.apache.http.annotation.ThreadSafe; import org.apache.http.auth.AuthSchemeProvider; import org.apache.http.auth.AuthState; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.CookieStore; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.Configurable; diff --git a/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java b/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java index 9ce942ae6..2722041f0 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultCredentialsProvider.java @@ -38,18 +38,18 @@ import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; import org.apache.http.auth.NTCredentials; import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.CredentialsStore; import org.apache.http.client.config.AuthSchemes; import org.apache.http.util.Args; /** - * Implementation of {@link CredentialsProvider} backed by standard + * Implementation of {@link CredentialsStore} backed by standard * JRE {@link Authenticator}. * * @since 4.3 */ @ThreadSafe -public class SystemDefaultCredentialsProvider implements CredentialsProvider { +public class SystemDefaultCredentialsProvider implements CredentialsStore { private static final Map SCHEME_MAP; diff --git a/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java b/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java index c0fbc9c35..bacc42204 100644 --- a/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java +++ b/httpclient/src/main/java/org/apache/http/impl/execchain/ProtocolExec.java @@ -39,8 +39,9 @@ import org.apache.http.HttpRequest; import org.apache.http.ProtocolException; import org.apache.http.annotation.Immutable; import org.apache.http.auth.AuthScope; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.CredentialsStore; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpExecutionAware; import org.apache.http.client.methods.HttpRequestWrapper; @@ -48,7 +49,6 @@ import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.client.utils.URIUtils; import org.apache.http.conn.routing.HttpRoute; -import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.protocol.HttpCoreContext; import org.apache.http.protocol.HttpProcessor; import org.apache.http.util.Args; @@ -142,14 +142,12 @@ public class ProtocolExec implements ClientExecChain { if (uri != null) { final String userinfo = uri.getUserInfo(); if (userinfo != null) { - CredentialsProvider credsProvider = context.getCredentialsProvider(); - if (credsProvider == null) { - credsProvider = new BasicCredentialsProvider(); - context.setCredentialsProvider(credsProvider); + final CredentialsProvider credsProvider = context.getCredentialsProvider(); + if (credsProvider instanceof CredentialsStore) { + ((CredentialsStore) credsProvider).setCredentials( + new AuthScope(target), + new UsernamePasswordCredentials(userinfo)); } - credsProvider.setCredentials( - new AuthScope(target), - new UsernamePasswordCredentials(userinfo)); } } diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestAuthenticationStrategy.java b/httpclient/src/test/java/org/apache/http/impl/client/TestAuthenticationStrategy.java index 73a8b643a..0d0d772bf 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/TestAuthenticationStrategy.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/TestAuthenticationStrategy.java @@ -41,9 +41,9 @@ import org.apache.http.auth.AuthOption; import org.apache.http.auth.AuthScheme; import org.apache.http.auth.AuthSchemeProvider; import org.apache.http.auth.AuthScope; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.AuthCache; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.AuthSchemes; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.protocol.HttpClientContext; @@ -227,7 +227,7 @@ public class TestAuthenticationStrategy { .register("digest", new DigestSchemeFactory()).build(); context.setAuthSchemeRegistry(authSchemeRegistry); - final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope("somehost", 80, "realm2"), new UsernamePasswordCredentials("user", "pwd")); context.setCredentialsProvider(credentialsProvider); @@ -256,7 +256,7 @@ public class TestAuthenticationStrategy { .register("digest", new DigestSchemeFactory()).build(); context.setAuthSchemeRegistry(authSchemeRegistry); - final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope("somehost", 80), new UsernamePasswordCredentials("user", "pwd")); context.setCredentialsProvider(credentialsProvider); @@ -291,7 +291,7 @@ public class TestAuthenticationStrategy { context.setAuthSchemeRegistry(authSchemeRegistry); context.setRequestConfig(config); - final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope("somehost", 80), new UsernamePasswordCredentials("user", "pwd")); context.setCredentialsProvider(credentialsProvider); diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestInternalHttpClient.java b/httpclient/src/test/java/org/apache/http/impl/client/TestInternalHttpClient.java index 9567073c5..a8d68f31f 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/TestInternalHttpClient.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/TestInternalHttpClient.java @@ -33,9 +33,9 @@ import java.util.Arrays; import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.auth.AuthSchemeProvider; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.CookieStore; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpRequestWrapper; diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java index 4cb082f23..92300cb29 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java @@ -41,10 +41,10 @@ import org.apache.http.HttpStatus; import org.apache.http.auth.AUTH; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.AuthCache; import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.NonRepeatableRequestException; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; @@ -149,20 +149,12 @@ public class TestClientAuthentication extends LocalServerTestBase { this.creds = creds; } - @Override - public void clear() { - } - @Override public Credentials getCredentials(final AuthScope authscope) { this.authscope = authscope; return this.creds; } - @Override - public void setCredentials(final AuthScope authscope, final Credentials credentials) { - } - public AuthScope getAuthScope() { return this.authscope; } diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java index d4117acfa..c04805b7b 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthenticationFallBack.java @@ -39,8 +39,8 @@ import org.apache.http.HttpStatus; import org.apache.http.auth.AUTH; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.entity.StringEntity; @@ -117,20 +117,12 @@ public class TestClientAuthenticationFallBack extends LocalServerTestBase { this.creds = creds; } - @Override - public void clear() { - } - @Override public Credentials getCredentials(final AuthScope authscope) { this.authscope = authscope; return this.creds; } - @Override - public void setCredentials(final AuthScope authscope, final Credentials credentials) { - } - public AuthScope getAuthScope() { return this.authscope; } diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java index e9897c5b0..c4e327570 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java @@ -43,8 +43,8 @@ import org.apache.http.auth.AuthScheme; import org.apache.http.auth.AuthSchemeProvider; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.protocol.HttpClientContext; @@ -133,24 +133,12 @@ public class TestClientReauthentication extends LocalServerTestBase { this.creds = creds; } - @Override - public void clear() { - } - @Override public Credentials getCredentials(final AuthScope authscope) { this.authscope = authscope; return this.creds; } - @Override - public void setCredentials(final AuthScope authscope, final Credentials credentials) { - } - - public AuthScope getAuthScope() { - return this.authscope; - } - } @Test diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java index f6380313e..a475dcd8c 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java @@ -38,7 +38,6 @@ import org.apache.http.auth.AuthScheme; import org.apache.http.auth.AuthSchemeProvider; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; -import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.AuthSchemes; import org.apache.http.client.methods.HttpGet; import org.apache.http.config.Registry; @@ -155,7 +154,7 @@ public class TestSPNegoScheme extends LocalServerTestBase { final HttpHost target = start(); final AuthSchemeProvider nsf = new NegotiateSchemeProviderWithMockGssManager(); - final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); final Credentials use_jaas_creds = new UseJaasCredentials(); credentialsProvider.setCredentials(new AuthScope(null, -1, null), use_jaas_creds); @@ -186,7 +185,7 @@ public class TestSPNegoScheme extends LocalServerTestBase { final AuthSchemeProvider nsf = new NegotiateSchemeProviderWithMockGssManager(); - final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); final Credentials use_jaas_creds = new UseJaasCredentials(); credentialsProvider.setCredentials(new AuthScope(null, -1, null), use_jaas_creds); diff --git a/httpclient/src/test/java/org/apache/http/impl/execchain/TestProtocolExec.java b/httpclient/src/test/java/org/apache/http/impl/execchain/TestProtocolExec.java index 150393b6b..c7e763b2c 100644 --- a/httpclient/src/test/java/org/apache/http/impl/execchain/TestProtocolExec.java +++ b/httpclient/src/test/java/org/apache/http/impl/execchain/TestProtocolExec.java @@ -33,13 +33,14 @@ import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; -import org.apache.http.client.CredentialsProvider; +import org.apache.http.auth.CredentialsProvider; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpExecutionAware; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpRequestWrapper; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.conn.routing.HttpRoute; +import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.message.BasicHttpRequest; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpProcessor; @@ -185,11 +186,11 @@ public class TestProtocolExec { final HttpRequestWrapper request = HttpRequestWrapper.wrap( new HttpGet("http://somefella:secret@bar/test")); final HttpClientContext context = HttpClientContext.create(); + context.setCredentialsProvider(new BasicCredentialsProvider()); protocolExec.execute(route, request, context, execAware); Assert.assertEquals(new URI("/test"), request.getURI()); Assert.assertEquals(new HttpHost("bar", -1), context.getTargetHost()); final CredentialsProvider credentialsProvider = context.getCredentialsProvider(); - Assert.assertNotNull(credentialsProvider); final Credentials creds = credentialsProvider.getCredentials(new AuthScope("bar", -1, null)); Assert.assertNotNull(creds); Assert.assertEquals("somefella", creds.getUserPrincipal().getName());