diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSPNegoScheme.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSPNegoScheme.java index b765a53f3..2f859ebe2 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSPNegoScheme.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestSPNegoScheme.java @@ -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 authSchemeRegistry = RegistryBuilder.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 authSchemeRegistry = RegistryBuilder.create() - .register(AuthSchemes.SPNEGO, nsf) + .register(AuthSchemes.SPNEGO.ident, nsf) .build(); this.httpclient = HttpClients.custom() .setDefaultAuthSchemeRegistry(authSchemeRegistry) diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestWindowsNegotiateScheme.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestWindowsNegotiateScheme.java index d6ecb47e2..6a57912d9 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestWindowsNegotiateScheme.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestWindowsNegotiateScheme.java @@ -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 authSchemeRegistry = RegistryBuilder.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()); } } diff --git a/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WinHttpClients.java b/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WinHttpClients.java index f5db1e900..1d57c5d28 100644 --- a/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WinHttpClients.java +++ b/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WinHttpClients.java @@ -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 authSchemeRegistry = RegistryBuilder.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); diff --git a/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNTLMSchemeFactory.java b/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNTLMSchemeFactory.java index 0615cdba8..0f6d997ac 100644 --- a/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNTLMSchemeFactory.java +++ b/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNTLMSchemeFactory.java @@ -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); } } diff --git a/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNegotiateScheme.java b/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNegotiateScheme.java index e7d2b91ff..34a8936a7 100644 --- a/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNegotiateScheme.java +++ b/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNegotiateScheme.java @@ -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; diff --git a/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNegotiateSchemeFactory.java b/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNegotiateSchemeFactory.java index 96379ee3a..d43c99469 100644 --- a/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNegotiateSchemeFactory.java +++ b/httpclient5-win/src/main/java/org/apache/hc/client5/http/impl/win/WindowsNegotiateSchemeFactory.java @@ -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); } } diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java index 0a282b5cb..8b42e5bff 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientConfiguration.java @@ -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. diff --git a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java index 78727c5f4..eed530d43 100644 --- a/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java +++ b/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientCustomPublicSuffixList.java @@ -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 cookieSpecRegistry = RegistryBuilder.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(), diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/config/AuthSchemes.java b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/AuthSchemes.java similarity index 76% rename from httpclient5/src/main/java/org/apache/hc/client5/http/config/AuthSchemes.java rename to httpclient5/src/main/java/org/apache/hc/client5/http/auth/AuthSchemes.java index f18d40408..9819883fe 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/config/AuthSchemes.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/AuthSchemes.java @@ -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; } -} +} \ No newline at end of file diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/config/CookieSpecs.java b/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/CookieSpecs.java similarity index 65% rename from httpclient5/src/main/java/org/apache/hc/client5/http/config/CookieSpecs.java rename to httpclient5/src/main/java/org/apache/hc/client5/http/cookie/CookieSpecs.java index 5c2465f7c..5b46fac8c 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/config/CookieSpecs.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/CookieSpecs.java @@ -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; } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/AuthSupport.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/AuthSupport.java index 31cfc387d..67d3b3536 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/AuthSupport.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/AuthSupport.java @@ -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)); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/CookieSpecRegistries.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/CookieSpecRegistries.java index c114e05b4..5d1063e79 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/CookieSpecRegistries.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/CookieSpecRegistries.java @@ -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 createDefaultBuilder(final PublicSuffixMatcher publicSuffixMatcher) { - final CookieSpecProvider laxStandardProvider = new RFC6265CookieSpecProvider( - RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, publicSuffixMatcher); - final CookieSpecProvider strictStandardProvider = new RFC6265CookieSpecProvider( - RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, publicSuffixMatcher); return RegistryBuilder.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()); } /** diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultAuthenticationStrategy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultAuthenticationStrategy.java index bfcf98ffe..73ad51c23 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultAuthenticationStrategy.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultAuthenticationStrategy.java @@ -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 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 select( diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncClientBuilder.java index fa26fac8f..e1f1cbe34 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncClientBuilder.java @@ -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 authSchemeRegistryCopy = this.authSchemeRegistry; if (authSchemeRegistryCopy == null) { authSchemeRegistryCopy = RegistryBuilder.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 cookieSpecRegistryCopy = this.cookieSpecRegistry; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java index 525aa4a18..7cbb91859 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java @@ -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 authSchemeRegistryCopy = this.authSchemeRegistry; if (authSchemeRegistryCopy == null) { authSchemeRegistryCopy = RegistryBuilder.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 cookieSpecRegistryCopy = this.cookieSpecRegistry; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/SystemDefaultCredentialsProvider.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/SystemDefaultCredentialsProvider.java index 114f1ee10..90e641ab2 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/SystemDefaultCredentialsProvider.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/SystemDefaultCredentialsProvider.java @@ -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); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java index a2220401e..4d25d70ed 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java @@ -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 authSchemeRegistryCopy = this.authSchemeRegistry; if (authSchemeRegistryCopy == null) { authSchemeRegistryCopy = RegistryBuilder.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 cookieSpecRegistryCopy = this.cookieSpecRegistry; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java index c68ee4acb..7be98fb46 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java @@ -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.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(); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestAddCookies.java b/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestAddCookies.java index d64a6c7d6..7d311035d 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestAddCookies.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestAddCookies.java @@ -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); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java b/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java index 739239948..da7b7ca54 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java @@ -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()); } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestAuthenticationStrategy.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestAuthenticationStrategy.java index 91a4d4c69..98a5207bc 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestAuthenticationStrategy.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestAuthenticationStrategy.java @@ -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(); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestHttpAuthenticator.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestHttpAuthenticator.java index 110e6bbc6..2f510e0d5 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestHttpAuthenticator.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestHttpAuthenticator.java @@ -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; } } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAddCookies.java b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAddCookies.java index 343158f11..160a264d7 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAddCookies.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAddCookies.java @@ -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.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();