Redesign of CredentialsProvider interface
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1687908 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d5c520a8e1
commit
fb56b49465
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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.
|
||||
* <p>
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
package org.apache.http.auth;
|
||||
|
||||
/**
|
||||
* Provider of authentication credentials.
|
||||
* <p>
|
||||
* 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);
|
||||
|
||||
}
|
|
@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
*/
|
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<AuthScope, Credentials> credMap;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<String, String> SCHEME_MAP;
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue