Use enums for supported cookie policies and auth schemes

This commit is contained in:
Oleg Kalnichevski 2018-10-14 20:01:08 +02:00
parent 9e8ab71517
commit ac90342039
23 changed files with 129 additions and 138 deletions

View File

@ -36,7 +36,7 @@ import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.Credentials;
import org.apache.hc.client5.http.auth.KerberosConfig;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
import org.apache.hc.client5.http.impl.auth.SPNegoScheme;
import org.apache.hc.client5.http.impl.classic.HttpClients;
@ -160,7 +160,7 @@ public class TestSPNegoScheme extends LocalServerTestBase {
credentialsProvider.setCredentials(new AuthScope(null, null, -1, null, null), use_jaas_creds);
final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.SPNEGO, nsf)
.register(AuthSchemes.SPNEGO.ident, nsf)
.build();
this.httpclient = HttpClients.custom()
.setDefaultAuthSchemeRegistry(authSchemeRegistry)
@ -191,7 +191,7 @@ public class TestSPNegoScheme extends LocalServerTestBase {
credentialsProvider.setCredentials(new AuthScope(null, null, -1, null, null), use_jaas_creds);
final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.SPNEGO, nsf)
.register(AuthSchemes.SPNEGO.ident, nsf)
.build();
this.httpclient = HttpClients.custom()
.setDefaultAuthSchemeRegistry(authSchemeRegistry)

View File

@ -31,7 +31,7 @@ import java.io.IOException;
import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemeProvider;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
@ -81,10 +81,10 @@ public class TestWindowsNegotiateScheme extends LocalServerTestBase {
// you can contact the server that authenticated you." is associated with SEC_E_DOWNGRADE_DETECTED.
final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.SPNEGO, new AuthSchemeProvider() {
.register(AuthSchemes.SPNEGO.ident, new AuthSchemeProvider() {
@Override
public AuthScheme create(final HttpContext context) {
return new WindowsNegotiateSchemeGetTokenFail(AuthSchemes.SPNEGO, "HTTP/example.com");
return new WindowsNegotiateSchemeGetTokenFail(AuthSchemes.SPNEGO.ident, "HTTP/example.com");
}
}).build();
final CloseableHttpClient customClient = HttpClientBuilder.create()
@ -92,7 +92,7 @@ public class TestWindowsNegotiateScheme extends LocalServerTestBase {
final HttpHost target = start();
final HttpGet httpGet = new HttpGet("/");
try (CloseableHttpResponse response = customClient.execute(target, httpGet)) {
try (final CloseableHttpResponse response = customClient.execute(target, httpGet)) {
EntityUtils.consume(response.getEntity());
}
}

View File

@ -29,7 +29,7 @@ package org.apache.hc.client5.http.impl.win;
import java.util.Locale;
import org.apache.hc.client5.http.auth.AuthSchemeProvider;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.impl.auth.BasicSchemeFactory;
import org.apache.hc.client5.http.impl.auth.DigestSchemeFactory;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
@ -67,10 +67,10 @@ public class WinHttpClients {
private static HttpClientBuilder createBuilder() {
if (isWinAuthAvailable()) {
final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.BASIC, new BasicSchemeFactory())
.register(AuthSchemes.DIGEST, new DigestSchemeFactory())
.register(AuthSchemes.NTLM, new WindowsNTLMSchemeFactory(null))
.register(AuthSchemes.SPNEGO, new WindowsNegotiateSchemeFactory(null))
.register(AuthSchemes.BASIC.ident, new BasicSchemeFactory())
.register(AuthSchemes.DIGEST.ident, new DigestSchemeFactory())
.register(AuthSchemes.NTLM.ident, new WindowsNTLMSchemeFactory(null))
.register(AuthSchemes.SPNEGO.ident, new WindowsNegotiateSchemeFactory(null))
.build();
return HttpClientBuilder.create()
.setDefaultAuthSchemeRegistry(authSchemeRegistry);

View File

@ -29,7 +29,7 @@ package org.apache.hc.client5.http.impl.win;
import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemeProvider;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.protocol.HttpContext;
@ -55,7 +55,7 @@ public class WindowsNTLMSchemeFactory implements AuthSchemeProvider {
@Override
public AuthScheme create(final HttpContext context) {
return new WindowsNegotiateScheme(AuthSchemes.NTLM, servicePrincipalName);
return new WindowsNegotiateScheme(AuthSchemes.NTLM.ident, servicePrincipalName);
}
}

View File

@ -37,7 +37,7 @@ import org.apache.hc.client5.http.auth.BasicUserPrincipal;
import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.auth.MalformedChallengeException;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
@ -83,10 +83,10 @@ public class WindowsNegotiateScheme implements AuthScheme {
private CtxtHandle sspiContext;
private boolean continueNeeded;
public WindowsNegotiateScheme(final String scheme, final String servicePrincipalName) {
WindowsNegotiateScheme(final String scheme, final String servicePrincipalName) {
super();
this.scheme = (scheme == null) ? AuthSchemes.SPNEGO : scheme;
this.scheme = (scheme == null) ? AuthSchemes.SPNEGO.ident : scheme;
this.continueNeeded = true;
this.servicePrincipalName = servicePrincipalName;

View File

@ -29,7 +29,7 @@ package org.apache.hc.client5.http.impl.win;
import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemeProvider;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.protocol.HttpContext;
@ -55,7 +55,7 @@ public class WindowsNegotiateSchemeFactory implements AuthSchemeProvider {
@Override
public AuthScheme create(final HttpContext context) {
return new WindowsNegotiateScheme(AuthSchemes.SPNEGO, servicePrincipalName);
return new WindowsNegotiateScheme(AuthSchemes.SPNEGO.ident, servicePrincipalName);
}
}

View File

@ -38,10 +38,10 @@ import javax.net.ssl.SSLContext;
import org.apache.hc.client5.http.DnsResolver;
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.SystemDefaultDnsResolver;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.config.CookieSpecs;
import org.apache.hc.client5.http.cookie.CookieSpecs;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.BasicCookieStore;
import org.apache.hc.client5.http.cookie.CookieStore;
@ -193,10 +193,10 @@ public class ClientConfiguration {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
// Create global request configuration
final RequestConfig defaultRequestConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.DEFAULT)
.setCookieSpec(CookieSpecs.STANDARD.ident)
.setExpectContinueEnabled(true)
.setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
.setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
.setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM.ident, AuthSchemes.DIGEST.ident))
.setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC.ident))
.build();
// Create an HttpClient with the given custom dependencies and configuration.

View File

@ -29,7 +29,7 @@ package org.apache.hc.client5.http.examples;
import java.net.URL;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.config.CookieSpecs;
import org.apache.hc.client5.http.cookie.CookieSpecs;
import org.apache.hc.client5.http.cookie.CookieSpecProvider;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
@ -63,9 +63,8 @@ public class ClientCustomPublicSuffixList {
final RFC6265CookieSpecProvider cookieSpecProvider = new RFC6265CookieSpecProvider(publicSuffixMatcher);
final Lookup<CookieSpecProvider> cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
.register(CookieSpecs.DEFAULT, cookieSpecProvider)
.register(CookieSpecs.STANDARD, cookieSpecProvider)
.register(CookieSpecs.STANDARD_STRICT, cookieSpecProvider)
.register(CookieSpecs.STANDARD.ident, cookieSpecProvider)
.register(CookieSpecs.STANDARD_STRICT.ident, cookieSpecProvider)
.build();
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
SSLContexts.createDefault(),

View File

@ -25,56 +25,55 @@
*
*/
package org.apache.hc.client5.http.config;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
package org.apache.hc.client5.http.auth;
/**
* Standard authentication schemes supported by HttpClient.
* Supported authentication schemes.
*
* @since 4.3
*/
@Contract(threading = ThreadingBehavior.IMMUTABLE)
public final class AuthSchemes {
public enum AuthSchemes {
/**
* Basic authentication scheme as defined in RFC 2617 (considered inherently
* insecure, but most widely supported).
*/
public static final String BASIC = "Basic";
BASIC("Basic"),
/**
* Digest authentication scheme as defined in RFC 2617.
*/
public static final String DIGEST = "Digest";
DIGEST("Digest"),
/**
* The NTLM authentication scheme is a proprietary Microsoft Windows
* authentication protocol as defined in [MS-NLMP].
*/
public static final String NTLM = "NTLM";
NTLM("NTLM"),
/**
* SPNEGO authentication scheme as defined in RFC 4559 and RFC 4178
* (considered to be the most secure among currently supported
* authentication schemes if Kerberos is selected).
*/
public static final String SPNEGO = "Negotiate";
SPNEGO("Negotiate"),
/**
* Kerberos authentication scheme as defined in RFC 4120
* (considered to be the most secure among currently supported
* authentication schemes).
*/
public static final String KERBEROS = "Kerberos";
KERBEROS("Kerberos"),
/**
* CredSSP authentication scheme defined in [MS-CSSP].
*/
public static final String CREDSSP = "CredSSP";
CREDSSP("CredSSP");
private AuthSchemes() {
public final String ident;
AuthSchemes(final String ident) {
this.ident = ident;
}
}
}

View File

@ -25,44 +25,36 @@
*
*/
package org.apache.hc.client5.http.config;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
package org.apache.hc.client5.http.cookie;
/**
* Standard cookie specifications supported by HttpClient.
* Supported cookie specifications.
*
* @since 4.3
*/
@Contract(threading = ThreadingBehavior.IMMUTABLE)
public final class CookieSpecs {
public enum CookieSpecs {
/**
* The RFC 6265 compliant policy (interoprability profile).
*/
public static final String STANDARD = "standard";
STANDARD("standard"),
/**
* The RFC 6265 compliant policy (strict profile).
*
* @since 4.4
*/
public static final String STANDARD_STRICT = "standard-strict";
/**
* The default policy. This policy provides a higher degree of compatibility
* with common cookie management of popular HTTP agents for non-standard
* (Netscape style) cookies.
*/
public static final String DEFAULT = "default";
STANDARD_STRICT("standard-strict"),
/**
* The policy that ignores cookies.
*/
public static final String IGNORE_COOKIES = "ignoreCookies";
IGNORE_COOKIES("ignoreCookies");
private CookieSpecs() {
public final String ident;
CookieSpecs(final String ident) {
this.ident = ident;
}
}

View File

@ -31,7 +31,7 @@ import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.CredentialsStore;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.net.URIAuthority;
@ -65,7 +65,7 @@ public class AuthSupport {
password = null;
}
credentialsStore.setCredentials(
new AuthScope(scheme, authority.getHostName(), authority.getPort(), null, AuthSchemes.BASIC),
new AuthScope(scheme, authority.getHostName(), authority.getPort(), null, AuthSchemes.BASIC.ident),
new UsernamePasswordCredentials(userName, password));
}

View File

@ -27,7 +27,7 @@
package org.apache.hc.client5.http.impl;
import org.apache.hc.client5.http.config.CookieSpecs;
import org.apache.hc.client5.http.cookie.CookieSpecs;
import org.apache.hc.client5.http.cookie.CookieSpecProvider;
import org.apache.hc.client5.http.impl.cookie.IgnoreSpecProvider;
import org.apache.hc.client5.http.impl.cookie.RFC6265CookieSpecProvider;
@ -45,15 +45,12 @@ public final class CookieSpecRegistries {
* Creates a builder containing the default registry entries, using the provided public suffix matcher.
*/
public static RegistryBuilder<CookieSpecProvider> createDefaultBuilder(final PublicSuffixMatcher publicSuffixMatcher) {
final CookieSpecProvider laxStandardProvider = new RFC6265CookieSpecProvider(
RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, publicSuffixMatcher);
final CookieSpecProvider strictStandardProvider = new RFC6265CookieSpecProvider(
RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, publicSuffixMatcher);
return RegistryBuilder.<CookieSpecProvider>create()
.register(CookieSpecs.DEFAULT, laxStandardProvider)
.register(CookieSpecs.STANDARD, laxStandardProvider)
.register(CookieSpecs.STANDARD_STRICT, strictStandardProvider)
.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider());
.register(CookieSpecs.STANDARD.ident, new RFC6265CookieSpecProvider(
RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, publicSuffixMatcher))
.register(CookieSpecs.STANDARD_STRICT.ident, new RFC6265CookieSpecProvider(
RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, publicSuffixMatcher))
.register(CookieSpecs.IGNORE_COOKIES.ident, new IgnoreSpecProvider());
}
/**

View File

@ -40,7 +40,7 @@ import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemeProvider;
import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.annotation.Contract;
@ -65,12 +65,12 @@ public class DefaultAuthenticationStrategy implements AuthenticationStrategy {
private static final List<String> DEFAULT_SCHEME_PRIORITY =
Collections.unmodifiableList(Arrays.asList(
AuthSchemes.SPNEGO,
AuthSchemes.KERBEROS,
AuthSchemes.NTLM,
AuthSchemes.CREDSSP,
AuthSchemes.DIGEST,
AuthSchemes.BASIC));
AuthSchemes.SPNEGO.ident,
AuthSchemes.KERBEROS.ident,
AuthSchemes.NTLM.ident,
AuthSchemes.CREDSSP.ident,
AuthSchemes.DIGEST.ident,
AuthSchemes.BASIC.ident));
@Override
public List<AuthScheme> select(

View File

@ -47,7 +47,7 @@ import org.apache.hc.client5.http.async.AsyncExecChainHandler;
import org.apache.hc.client5.http.auth.AuthSchemeProvider;
import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.auth.KerberosConfig;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.BasicCookieStore;
import org.apache.hc.client5.http.cookie.CookieSpecProvider;
@ -757,12 +757,14 @@ public class Http2AsyncClientBuilder {
Lookup<AuthSchemeProvider> authSchemeRegistryCopy = this.authSchemeRegistry;
if (authSchemeRegistryCopy == null) {
authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.BASIC, new BasicSchemeFactory())
.register(AuthSchemes.DIGEST, new DigestSchemeFactory())
.register(AuthSchemes.CREDSSP, new CredSspSchemeFactory())
.register(AuthSchemes.NTLM, new NTLMSchemeFactory())
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.register(AuthSchemes.BASIC.ident, new BasicSchemeFactory())
.register(AuthSchemes.DIGEST.ident, new DigestSchemeFactory())
.register(AuthSchemes.CREDSSP.ident, new CredSspSchemeFactory())
.register(AuthSchemes.NTLM.ident, new NTLMSchemeFactory())
.register(AuthSchemes.SPNEGO.ident,
new SPNegoSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.register(AuthSchemes.KERBEROS.ident,
new KerberosSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.build();
}
Lookup<CookieSpecProvider> cookieSpecRegistryCopy = this.cookieSpecRegistry;

View File

@ -48,7 +48,7 @@ import org.apache.hc.client5.http.async.AsyncExecChainHandler;
import org.apache.hc.client5.http.auth.AuthSchemeProvider;
import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.auth.KerberosConfig;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.BasicCookieStore;
import org.apache.hc.client5.http.cookie.CookieSpecProvider;
@ -963,12 +963,14 @@ public class HttpAsyncClientBuilder {
Lookup<AuthSchemeProvider> authSchemeRegistryCopy = this.authSchemeRegistry;
if (authSchemeRegistryCopy == null) {
authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.BASIC, new BasicSchemeFactory())
.register(AuthSchemes.DIGEST, new DigestSchemeFactory())
.register(AuthSchemes.CREDSSP, new CredSspSchemeFactory())
.register(AuthSchemes.NTLM, new NTLMSchemeFactory())
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.register(AuthSchemes.BASIC.ident, new BasicSchemeFactory())
.register(AuthSchemes.DIGEST.ident, new DigestSchemeFactory())
.register(AuthSchemes.CREDSSP.ident, new CredSspSchemeFactory())
.register(AuthSchemes.NTLM.ident, new NTLMSchemeFactory())
.register(AuthSchemes.SPNEGO.ident,
new SPNegoSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.register(AuthSchemes.KERBEROS.ident,
new KerberosSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.build();
}
Lookup<CookieSpecProvider> cookieSpecRegistryCopy = this.cookieSpecRegistry;

View File

@ -32,7 +32,6 @@ import java.net.PasswordAuthentication;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -41,7 +40,7 @@ import org.apache.hc.client5.http.auth.Credentials;
import org.apache.hc.client5.http.auth.CredentialsStore;
import org.apache.hc.client5.http.auth.NTCredentials;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
@ -63,11 +62,11 @@ public class SystemDefaultCredentialsProvider implements CredentialsStore {
static {
SCHEME_MAP = new ConcurrentHashMap<>();
SCHEME_MAP.put(AuthSchemes.BASIC.toUpperCase(Locale.ROOT), "Basic");
SCHEME_MAP.put(AuthSchemes.DIGEST.toUpperCase(Locale.ROOT), "Digest");
SCHEME_MAP.put(AuthSchemes.NTLM.toUpperCase(Locale.ROOT), "NTLM");
SCHEME_MAP.put(AuthSchemes.SPNEGO.toUpperCase(Locale.ROOT), "SPNEGO");
SCHEME_MAP.put(AuthSchemes.KERBEROS.toUpperCase(Locale.ROOT), "Kerberos");
SCHEME_MAP.put(AuthSchemes.BASIC.name(), "Basic");
SCHEME_MAP.put(AuthSchemes.DIGEST.name(), "Digest");
SCHEME_MAP.put(AuthSchemes.NTLM.name(), "NTLM");
SCHEME_MAP.put(AuthSchemes.SPNEGO.name(), "SPNEGO");
SCHEME_MAP.put(AuthSchemes.KERBEROS.name(), "Kerberos");
}
private static String translateAuthScheme(final String key) {
@ -159,7 +158,7 @@ public class SystemDefaultCredentialsProvider implements CredentialsStore {
if (domain != null) {
return new NTCredentials(systemcreds.getUserName(), systemcreds.getPassword(), null, domain);
}
if (AuthSchemes.NTLM.equalsIgnoreCase(authscope.getAuthScheme())) {
if (AuthSchemes.NTLM.ident.equalsIgnoreCase(authscope.getAuthScheme())) {
// Domain may be specified in a fully qualified user name
return new NTCredentials(
systemcreds.getUserName(), systemcreds.getPassword(), null, null);

View File

@ -51,7 +51,7 @@ import org.apache.hc.client5.http.auth.KerberosConfig;
import org.apache.hc.client5.http.classic.BackoffManager;
import org.apache.hc.client5.http.classic.ConnectionBackoffStrategy;
import org.apache.hc.client5.http.classic.ExecChainHandler;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.BasicCookieStore;
import org.apache.hc.client5.http.cookie.CookieSpecProvider;
@ -951,12 +951,12 @@ public class HttpClientBuilder {
Lookup<AuthSchemeProvider> authSchemeRegistryCopy = this.authSchemeRegistry;
if (authSchemeRegistryCopy == null) {
authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.BASIC, new BasicSchemeFactory())
.register(AuthSchemes.DIGEST, new DigestSchemeFactory())
.register(AuthSchemes.CREDSSP, new CredSspSchemeFactory())
.register(AuthSchemes.NTLM, new NTLMSchemeFactory())
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.register(AuthSchemes.BASIC.ident, new BasicSchemeFactory())
.register(AuthSchemes.DIGEST.ident, new DigestSchemeFactory())
.register(AuthSchemes.CREDSSP.ident, new CredSspSchemeFactory())
.register(AuthSchemes.NTLM.ident, new NTLMSchemeFactory())
.register(AuthSchemes.SPNEGO.ident, new SPNegoSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.register(AuthSchemes.KERBEROS.ident, new KerberosSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.build();
}
Lookup<CookieSpecProvider> cookieSpecRegistryCopy = this.cookieSpecRegistry;

View File

@ -41,7 +41,7 @@ import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.auth.Credentials;
import org.apache.hc.client5.http.auth.KerberosConfig;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy;
import org.apache.hc.client5.http.impl.TunnelRefusedException;
@ -115,11 +115,13 @@ public class ProxyClient {
this.authenticator = new HttpAuthenticator();
this.proxyAuthExchange = new AuthExchange();
this.authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.BASIC, new BasicSchemeFactory())
.register(AuthSchemes.DIGEST, new DigestSchemeFactory())
.register(AuthSchemes.NTLM, new NTLMSchemeFactory())
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.register(AuthSchemes.BASIC.ident, new BasicSchemeFactory())
.register(AuthSchemes.DIGEST.ident, new DigestSchemeFactory())
.register(AuthSchemes.NTLM.ident, new NTLMSchemeFactory())
.register(AuthSchemes.SPNEGO.ident,
new SPNegoSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.register(AuthSchemes.KERBEROS.ident,
new KerberosSchemeFactory(KerberosConfig.DEFAULT, SystemDefaultDnsResolver.INSTANCE))
.build();
this.reuseStrategy = new DefaultConnectionReuseStrategy();
}

View File

@ -33,7 +33,7 @@ import java.util.Date;
import java.util.List;
import org.apache.hc.client5.http.RouteInfo;
import org.apache.hc.client5.http.config.CookieSpecs;
import org.apache.hc.client5.http.cookie.CookieSpecs;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.Cookie;
import org.apache.hc.client5.http.cookie.CookieOrigin;
@ -108,7 +108,7 @@ public class RequestAddCookies implements HttpRequestInterceptor {
final RequestConfig config = clientContext.getRequestConfig();
String policy = config.getCookieSpec();
if (policy == null) {
policy = CookieSpecs.DEFAULT;
policy = CookieSpecs.STANDARD.ident;
}
if (this.log.isDebugEnabled()) {
this.log.debug("CookieSpec selected: " + policy);

View File

@ -27,9 +27,11 @@
package org.apache.hc.client5.http.config;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.cookie.CookieSpecs;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
@ -71,10 +73,10 @@ public class TestRequestConfig {
.setRedirectsEnabled(false)
.setCircularRedirectsAllowed(true)
.setMaxRedirects(100)
.setCookieSpec(CookieSpecs.STANDARD)
.setCookieSpec(CookieSpecs.STANDARD.ident)
.setProxy(new HttpHost("someproxy"))
.setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM))
.setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.DIGEST))
.setTargetPreferredAuthSchemes(Collections.singletonList(AuthSchemes.NTLM.ident))
.setProxyPreferredAuthSchemes(Collections.singletonList(AuthSchemes.DIGEST.ident))
.setContentCompressionEnabled(false)
.build();
final RequestConfig config = RequestConfig.copy(config0).build();
@ -85,10 +87,10 @@ public class TestRequestConfig {
Assert.assertEquals(false, config.isRedirectsEnabled());
Assert.assertEquals(true, config.isCircularRedirectsAllowed());
Assert.assertEquals(100, config.getMaxRedirects());
Assert.assertEquals(CookieSpecs.STANDARD, config.getCookieSpec());
Assert.assertEquals(CookieSpecs.STANDARD.ident, config.getCookieSpec());
Assert.assertEquals(new HttpHost("someproxy"), config.getProxy());
Assert.assertEquals(Arrays.asList(AuthSchemes.NTLM), config.getTargetPreferredAuthSchemes());
Assert.assertEquals(Arrays.asList(AuthSchemes.DIGEST), config.getProxyPreferredAuthSchemes());
Assert.assertEquals(Collections.singletonList(AuthSchemes.NTLM.ident), config.getTargetPreferredAuthSchemes());
Assert.assertEquals(Collections.singletonList(AuthSchemes.DIGEST.ident), config.getProxyPreferredAuthSchemes());
Assert.assertEquals(false, config.isContentCompressionEnabled());
}

View File

@ -26,7 +26,6 @@
*/
package org.apache.hc.client5.http.impl;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@ -38,7 +37,7 @@ import org.apache.hc.client5.http.auth.AuthSchemeProvider;
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
import org.apache.hc.client5.http.impl.auth.BasicScheme;
@ -131,7 +130,7 @@ public class TestAuthenticationStrategy {
public void testCustomAuthPreference() throws Exception {
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
final RequestConfig config = RequestConfig.custom()
.setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
.setTargetPreferredAuthSchemes(Collections.singletonList(AuthSchemes.BASIC.ident))
.build();
final HttpClientContext context = HttpClientContext.create();

View File

@ -40,7 +40,7 @@ import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.auth.Credentials;
import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.config.AuthSchemes;
import org.apache.hc.client5.http.auth.AuthSchemes;
import org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.HttpHeaders;
@ -69,7 +69,7 @@ public class TestHttpAuthenticator {
@Override
public String getName() {
return AuthSchemes.BASIC;
return AuthSchemes.BASIC.ident;
}
}

View File

@ -31,7 +31,7 @@ import java.util.Date;
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.RouteInfo.LayerType;
import org.apache.hc.client5.http.RouteInfo.TunnelType;
import org.apache.hc.client5.http.config.CookieSpecs;
import org.apache.hc.client5.http.cookie.CookieSpecs;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.BasicCookieStore;
import org.apache.hc.client5.http.cookie.CookieOrigin;
@ -75,15 +75,12 @@ public class TestRequestAddCookies {
cookie2.setPath("/");
this.cookieStore.addCookie(cookie2);
final CookieSpecProvider laxCookiePolicyPRovider = new RFC6265CookieSpecProvider(
RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, null);
final CookieSpecProvider strictCookiePolicyPRovider = new RFC6265CookieSpecProvider(
RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, null);
this.cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
.register(CookieSpecs.DEFAULT, laxCookiePolicyPRovider)
.register(CookieSpecs.STANDARD, laxCookiePolicyPRovider)
.register(CookieSpecs.STANDARD_STRICT, strictCookiePolicyPRovider)
.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider())
.register(CookieSpecs.STANDARD.ident, new RFC6265CookieSpecProvider(
RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, null))
.register(CookieSpecs.STANDARD_STRICT.ident, new RFC6265CookieSpecProvider(
RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, null))
.register(CookieSpecs.IGNORE_COOKIES.ident, new IgnoreSpecProvider())
.build();
}
@ -206,7 +203,8 @@ public class TestRequestAddCookies {
public void testAddCookiesUsingExplicitCookieSpec() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/");
final RequestConfig config = RequestConfig.custom()
.setCookieSpec(CookieSpecs.STANDARD_STRICT).build();
.setCookieSpec(CookieSpecs.STANDARD_STRICT.ident)
.build();
final HttpRoute route = new HttpRoute(this.target, null, false);
final HttpClientContext context = HttpClientContext.create();