[HTTPCLIENT-2046] Rename AuthSchemes enum to StandardAuthScheme final class

Modeled after StandardCharsets, the new class indicates a non-exhaustive
list of standard auth schemes by name supported by the HttpClient. The
previous enum suffered from two issues:

* it was exhaustive implying that no more auth schemes can be supported
* its sole purpose was to contain an id for the declared auth scheme;
  the enum values theirselves were never used directly

This closes #196
This commit is contained in:
Gary Gregory 2020-01-01 09:49:56 -05:00 committed by Michael Osipov
parent 54a341ea92
commit 634886ab61
42 changed files with 237 additions and 259 deletions

View File

@ -50,7 +50,7 @@ import java.util.List;
import org.apache.hc.client5.http.HttpRoute; import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse; import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.cache.CacheResponseStatus; import org.apache.hc.client5.http.cache.CacheResponseStatus;
import org.apache.hc.client5.http.cache.HttpCacheContext; import org.apache.hc.client5.http.cache.HttpCacheContext;
import org.apache.hc.client5.http.cache.HttpCacheEntry; import org.apache.hc.client5.http.cache.HttpCacheEntry;
@ -738,9 +738,9 @@ public abstract class TestCachingExecChain {
.setSharedCache(true).build()); .setSharedCache(true).build());
final Date now = new Date(); final Date now = new Date();
final ClassicHttpRequest req1 = new HttpOptions("http://foo.example.com/"); final ClassicHttpRequest req1 = new HttpOptions("http://foo.example.com/");
req1.setHeader("Authorization", AuthSchemes.BASIC.id + " QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); req1.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/"); final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
req2.setHeader("Authorization", AuthSchemes.BASIC.id + " QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); req2.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
final ClassicHttpResponse resp1 = new BasicClassicHttpResponse(HttpStatus.SC_NO_CONTENT, "No Content"); final ClassicHttpResponse resp1 = new BasicClassicHttpResponse(HttpStatus.SC_NO_CONTENT, "No Content");
resp1.setHeader("Content-Length", "0"); resp1.setHeader("Content-Length", "0");
resp1.setHeader("ETag", "\"options-etag\""); resp1.setHeader("ETag", "\"options-etag\"");

View File

@ -38,7 +38,7 @@ import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.classic.ExecChain; import org.apache.hc.client5.http.classic.ExecChain;
import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPost; import org.apache.hc.client5.http.classic.methods.HttpPost;
@ -612,7 +612,7 @@ public class TestProtocolRecommendations extends AbstractProtocolTest {
@Test @Test
public void testDoesNotModifyAuthorizationOnRequests() throws Exception { public void testDoesNotModifyAuthorizationOnRequests() throws Exception {
request.setHeader("Authorization", AuthSchemes.BASIC.id + " dXNlcjpwYXNzd2Q="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
testDoesNotModifyHeaderOnRequests("Authorization"); testDoesNotModifyHeaderOnRequests("Authorization");
} }

View File

@ -37,7 +37,7 @@ import java.util.regex.Pattern;
import org.apache.hc.client5.http.ClientProtocolException; import org.apache.hc.client5.http.ClientProtocolException;
import org.apache.hc.client5.http.HttpRoute; import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.cache.HttpCacheEntry; import org.apache.hc.client5.http.cache.HttpCacheEntry;
import org.apache.hc.client5.http.classic.ExecChain; import org.apache.hc.client5.http.classic.ExecChain;
import org.apache.hc.client5.http.utils.DateUtils; import org.apache.hc.client5.http.utils.DateUtils;
@ -4521,7 +4521,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
protected void testSharedCacheRevalidatesAuthorizedResponse( protected void testSharedCacheRevalidatesAuthorizedResponse(
final ClassicHttpResponse authorizedResponse, final int minTimes, final int maxTimes) throws Exception { final ClassicHttpResponse authorizedResponse, final int minTimes, final int maxTimes) throws Exception {
if (config.isSharedCache()) { if (config.isSharedCache()) {
final String authorization = AuthSchemes.BASIC.id + " dXNlcjpwYXNzd2Q="; final String authorization = StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=";
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/"); final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
req1.setHeader("Authorization",authorization); req1.setHeader("Authorization",authorization);
@ -4585,8 +4585,8 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
protected void testSharedCacheMustUseNewRequestHeadersWhenRevalidatingAuthorizedResponse( protected void testSharedCacheMustUseNewRequestHeadersWhenRevalidatingAuthorizedResponse(
final ClassicHttpResponse authorizedResponse) throws Exception { final ClassicHttpResponse authorizedResponse) throws Exception {
if (config.isSharedCache()) { if (config.isSharedCache()) {
final String authorization1 = AuthSchemes.BASIC.id + " dXNlcjpwYXNzd2Q="; final String authorization1 = StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=";
final String authorization2 = AuthSchemes.BASIC.id + " dXNlcjpwYXNzd2Qy"; final String authorization2 = StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Qy";
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/"); final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
req1.setHeader("Authorization",authorization1); req1.setHeader("Authorization",authorization1);

View File

@ -29,7 +29,7 @@ package org.apache.hc.client5.http.impl.cache;
import java.util.Date; import java.util.Date;
import java.util.Random; import java.util.Random;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.classic.methods.HttpOptions; import org.apache.hc.client5.http.classic.methods.HttpOptions;
import org.apache.hc.client5.http.utils.DateUtils; import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.http.HttpRequest; import org.apache.hc.core5.http.HttpRequest;
@ -83,7 +83,7 @@ public class TestResponseCachingPolicy {
@Test @Test
public void testResponsesToRequestsWithAuthorizationHeadersAreNotCacheableBySharedCache() { public void testResponsesToRequestsWithAuthorizationHeadersAreNotCacheableBySharedCache() {
request = new BasicHttpRequest("GET","/"); request = new BasicHttpRequest("GET","/");
request.setHeader("Authorization", AuthSchemes.BASIC.id + " dXNlcjpwYXNzd2Q="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
Assert.assertFalse(policy.isResponseCacheable(request,response)); Assert.assertFalse(policy.isResponseCacheable(request,response));
} }
@ -91,14 +91,14 @@ public class TestResponseCachingPolicy {
public void testResponsesToRequestsWithAuthorizationHeadersAreCacheableByNonSharedCache() { public void testResponsesToRequestsWithAuthorizationHeadersAreCacheableByNonSharedCache() {
policy = new ResponseCachingPolicy(0, false, false, false); policy = new ResponseCachingPolicy(0, false, false, false);
request = new BasicHttpRequest("GET","/"); request = new BasicHttpRequest("GET","/");
request.setHeader("Authorization", AuthSchemes.BASIC.id + " dXNlcjpwYXNzd2Q="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
Assert.assertTrue(policy.isResponseCacheable(request,response)); Assert.assertTrue(policy.isResponseCacheable(request,response));
} }
@Test @Test
public void testAuthorizedResponsesWithSMaxAgeAreCacheable() { public void testAuthorizedResponsesWithSMaxAgeAreCacheable() {
request = new BasicHttpRequest("GET","/"); request = new BasicHttpRequest("GET","/");
request.setHeader("Authorization", AuthSchemes.BASIC.id + " dXNlcjpwYXNzd2Q="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
response.setHeader("Cache-Control","s-maxage=3600"); response.setHeader("Cache-Control","s-maxage=3600");
Assert.assertTrue(policy.isResponseCacheable(request,response)); Assert.assertTrue(policy.isResponseCacheable(request,response));
} }
@ -106,7 +106,7 @@ public class TestResponseCachingPolicy {
@Test @Test
public void testAuthorizedResponsesWithMustRevalidateAreCacheable() { public void testAuthorizedResponsesWithMustRevalidateAreCacheable() {
request = new BasicHttpRequest("GET","/"); request = new BasicHttpRequest("GET","/");
request.setHeader("Authorization", AuthSchemes.BASIC.id + " dXNlcjpwYXNzd2Q="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
response.setHeader("Cache-Control","must-revalidate"); response.setHeader("Cache-Control","must-revalidate");
Assert.assertTrue(policy.isResponseCacheable(request,response)); Assert.assertTrue(policy.isResponseCacheable(request,response));
} }
@ -114,7 +114,7 @@ public class TestResponseCachingPolicy {
@Test @Test
public void testAuthorizedResponsesWithCacheControlPublicAreCacheable() { public void testAuthorizedResponsesWithCacheControlPublicAreCacheable() {
request = new BasicHttpRequest("GET","/"); request = new BasicHttpRequest("GET","/");
request.setHeader("Authorization", AuthSchemes.BASIC.id + " dXNlcjpwYXNzd2Q="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
response.setHeader("Cache-Control","public"); response.setHeader("Cache-Control","public");
Assert.assertTrue(policy.isResponseCacheable(request,response)); Assert.assertTrue(policy.isResponseCacheable(request,response));
} }
@ -122,7 +122,7 @@ public class TestResponseCachingPolicy {
@Test @Test
public void testAuthorizedResponsesWithCacheControlMaxAgeAreNotCacheable() { public void testAuthorizedResponsesWithCacheControlMaxAgeAreNotCacheable() {
request = new BasicHttpRequest("GET","/"); request = new BasicHttpRequest("GET","/");
request.setHeader("Authorization", AuthSchemes.BASIC.id + " dXNlcjpwYXNzd2Q="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
response.setHeader("Cache-Control","max-age=3600"); response.setHeader("Cache-Control","max-age=3600");
Assert.assertFalse(policy.isResponseCacheable(request,response)); Assert.assertFalse(policy.isResponseCacheable(request,response));
} }
@ -143,7 +143,7 @@ public class TestResponseCachingPolicy {
public void test206ResponseCodeIsNotCacheableUsingSharedPublicCache() { public void test206ResponseCodeIsNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false); policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", AuthSchemes.BASIC.id + " QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setCode(HttpStatus.SC_PARTIAL_CONTENT); response.setCode(HttpStatus.SC_PARTIAL_CONTENT);
response.setHeader("Cache-Control", "public"); response.setHeader("Cache-Control", "public");
Assert.assertFalse(policy.isResponseCacheable(request, response)); Assert.assertFalse(policy.isResponseCacheable(request, response));
@ -414,7 +414,7 @@ public class TestResponseCachingPolicy {
public void testVaryStarIsNotCacheableUsingSharedPublicCache() { public void testVaryStarIsNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false); policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", AuthSchemes.BASIC.id + " QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setHeader("Cache-Control", "public"); response.setHeader("Cache-Control", "public");
response.setHeader("Vary", "*"); response.setHeader("Vary", "*");
Assert.assertFalse(policy.isResponseCacheable(request, response)); Assert.assertFalse(policy.isResponseCacheable(request, response));
@ -446,7 +446,7 @@ public class TestResponseCachingPolicy {
policy = new ResponseCachingPolicy(0, true, false, false); policy = new ResponseCachingPolicy(0, true, false, false);
request = new HttpOptions("http://foo.example.com/"); request = new HttpOptions("http://foo.example.com/");
request.setHeader("Authorization", AuthSchemes.BASIC.id + " QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setCode(HttpStatus.SC_NO_CONTENT); response.setCode(HttpStatus.SC_NO_CONTENT);
response.setHeader("Cache-Control", "public"); response.setHeader("Cache-Control", "public");
@ -471,7 +471,7 @@ public class TestResponseCachingPolicy {
public void testResponsesWithMultipleAgeHeadersAreNotCacheableUsingSharedPublicCache() { public void testResponsesWithMultipleAgeHeadersAreNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false); policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", AuthSchemes.BASIC.id + " QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setHeader("Cache-Control", "public"); response.setHeader("Cache-Control", "public");
response.addHeader("Age", "3"); response.addHeader("Age", "3");
response.addHeader("Age", "5"); response.addHeader("Age", "5");
@ -489,7 +489,7 @@ public class TestResponseCachingPolicy {
public void testResponsesWithMultipleDateHeadersAreNotCacheableUsingSharedPublicCache() { public void testResponsesWithMultipleDateHeadersAreNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false); policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", AuthSchemes.BASIC.id + " QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setHeader("Cache-Control", "public"); response.setHeader("Cache-Control", "public");
response.addHeader("Date", DateUtils.formatDate(now)); response.addHeader("Date", DateUtils.formatDate(now));
response.addHeader("Date", DateUtils.formatDate(sixSecondsAgo)); response.addHeader("Date", DateUtils.formatDate(sixSecondsAgo));
@ -506,7 +506,7 @@ public class TestResponseCachingPolicy {
public void testResponsesWithMalformedDateHeadersAreNotCacheableUsingSharedPublicCache() { public void testResponsesWithMalformedDateHeadersAreNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false); policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", AuthSchemes.BASIC.id + " QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setHeader("Cache-Control", "public"); response.setHeader("Cache-Control", "public");
response.addHeader("Date", "garbage"); response.addHeader("Date", "garbage");
Assert.assertFalse(policy.isResponseCacheable(request, response)); Assert.assertFalse(policy.isResponseCacheable(request, response));
@ -523,7 +523,7 @@ public class TestResponseCachingPolicy {
public void testResponsesWithMultipleExpiresHeadersAreNotCacheableUsingSharedPublicCache() { public void testResponsesWithMultipleExpiresHeadersAreNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false); policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", AuthSchemes.BASIC.id + " QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setHeader("Cache-Control", "public"); response.setHeader("Cache-Control", "public");
response.addHeader("Expires", DateUtils.formatDate(now)); response.addHeader("Expires", DateUtils.formatDate(now));
response.addHeader("Expires", DateUtils.formatDate(sixSecondsAgo)); response.addHeader("Expires", DateUtils.formatDate(sixSecondsAgo));
@ -546,7 +546,7 @@ public class TestResponseCachingPolicy {
public void testResponseThatHasTooMuchContentIsNotCacheableUsingSharedPublicCache() { public void testResponseThatHasTooMuchContentIsNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false); policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", AuthSchemes.BASIC.id + " QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setHeader("Cache-Control", "public"); response.setHeader("Cache-Control", "public");
response.setHeader("Content-Length", "9000"); response.setHeader("Content-Length", "9000");
Assert.assertFalse(policy.isResponseCacheable(request, response)); Assert.assertFalse(policy.isResponseCacheable(request, response));

View File

@ -31,7 +31,7 @@ import java.nio.ByteBuffer;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.testing.auth.Authenticator; import org.apache.hc.client5.testing.auth.Authenticator;
import org.apache.hc.client5.testing.auth.BasicAuthTokenExtractor; import org.apache.hc.client5.testing.auth.BasicAuthTokenExtractor;
import org.apache.hc.core5.http.ContentType; import org.apache.hc.core5.http.ContentType;
@ -96,7 +96,7 @@ public class AuthenticatingAsyncDecorator implements AsyncServerExchangeHandler
} else { } else {
final HttpResponse unauthorized = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED); final HttpResponse unauthorized = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED);
final String realm = authenticator.getRealm(authority, requestUri); final String realm = authenticator.getRealm(authority, requestUri);
unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=\"" + realm + "\""); unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=\"" + realm + "\"");
customizeUnauthorizedResponse(unauthorized); customizeUnauthorizedResponse(unauthorized);

View File

@ -32,7 +32,7 @@ import java.nio.charset.StandardCharsets;
import org.apache.commons.codec.BinaryDecoder; import org.apache.commons.codec.BinaryDecoder;
import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.core5.http.HttpException; import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.ProtocolException; import org.apache.hc.core5.http.ProtocolException;
@ -45,7 +45,7 @@ public class BasicAuthTokenExtractor {
throw new ProtocolException("Invalid challenge response: " + challengeResponse); throw new ProtocolException("Invalid challenge response: " + challengeResponse);
} }
final String authscheme = challengeResponse.substring(0, i); final String authscheme = challengeResponse.substring(0, i);
if (authscheme.equalsIgnoreCase(AuthSchemes.BASIC.id)) { if (authscheme.equalsIgnoreCase(StandardAuthScheme.BASIC)) {
final String s = challengeResponse.substring(i + 1).trim(); final String s = challengeResponse.substring(i + 1).trim();
try { try {
final byte[] credsRaw = s.getBytes(StandardCharsets.US_ASCII); final byte[] credsRaw = s.getBytes(StandardCharsets.US_ASCII);

View File

@ -29,7 +29,7 @@ package org.apache.hc.client5.testing.classic;
import java.io.IOException; import java.io.IOException;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.testing.auth.Authenticator; import org.apache.hc.client5.testing.auth.Authenticator;
import org.apache.hc.client5.testing.auth.BasicAuthTokenExtractor; import org.apache.hc.client5.testing.auth.BasicAuthTokenExtractor;
import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.ClassicHttpRequest;
@ -84,7 +84,7 @@ public class AuthenticatingDecorator implements HttpServerRequestHandler {
} else { } else {
final ClassicHttpResponse unauthorized = new BasicClassicHttpResponse(HttpStatus.SC_UNAUTHORIZED); final ClassicHttpResponse unauthorized = new BasicClassicHttpResponse(HttpStatus.SC_UNAUTHORIZED);
final String realm = authenticator.getRealm(authority, requestUri); final String realm = authenticator.getRealm(authority, requestUri);
unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=\"" + realm + "\""); unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=\"" + realm + "\"");
customizeUnauthorizedResponse(unauthorized); customizeUnauthorizedResponse(unauthorized);
if (unauthorized.getEntity() == null) { if (unauthorized.getEntity() == null) {
unauthorized.setEntity(new StringEntity("Unauthorized")); unauthorized.setEntity(new StringEntity("Unauthorized"));

View File

@ -39,7 +39,7 @@ import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthScheme; import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemeFactory; import org.apache.hc.client5.http.auth.AuthSchemeFactory;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.ChallengeType; import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.auth.Credentials; import org.apache.hc.client5.http.auth.Credentials;
@ -539,7 +539,7 @@ public abstract class AbstractHttpAsyncClientAuthentication<T extends CloseableH
@Override @Override
protected void customizeUnauthorizedResponse(final HttpResponse unauthorized) { protected void customizeUnauthorizedResponse(final HttpResponse unauthorized) {
unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.DIGEST.id + " realm=\"test realm\" invalid"); unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.DIGEST + " realm=\"test realm\" invalid");
} }
}; };

View File

@ -39,7 +39,7 @@ import org.apache.hc.client5.http.auth.AuthCache;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthScheme; import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemeFactory; import org.apache.hc.client5.http.auth.AuthSchemeFactory;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.ChallengeType; import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.auth.Credentials; import org.apache.hc.client5.http.auth.Credentials;
@ -720,7 +720,7 @@ public class TestClientAuthentication extends LocalServerTestBase {
@Override @Override
protected void customizeUnauthorizedResponse(final ClassicHttpResponse unauthorized) { protected void customizeUnauthorizedResponse(final ClassicHttpResponse unauthorized) {
unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.DIGEST.id + " realm=\"test realm\" invalid"); unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.DIGEST + " realm=\"test realm\" invalid");
} }
}; };

View File

@ -28,7 +28,7 @@ package org.apache.hc.client5.testing.sync;
import java.io.IOException; import java.io.IOException;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.NTCredentials; import org.apache.hc.client5.http.auth.NTCredentials;
import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.classic.methods.HttpGet;
@ -61,7 +61,7 @@ public class TestClientAuthenticationFakeNTLM extends LocalServerTestBase {
final HttpContext context) throws HttpException, IOException { final HttpContext context) throws HttpException, IOException {
response.setCode(HttpStatus.SC_UNAUTHORIZED); response.setCode(HttpStatus.SC_UNAUTHORIZED);
response.setHeader("Connection", "Keep-Alive"); response.setHeader("Connection", "Keep-Alive");
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.NTLM.id); response.setHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.NTLM);
} }
} }
@ -93,7 +93,7 @@ public class TestClientAuthenticationFakeNTLM extends LocalServerTestBase {
private final String authenticateHeaderValue; private final String authenticateHeaderValue;
public NtlmType2MessageResponseHandler(final String type2Message) { public NtlmType2MessageResponseHandler(final String type2Message) {
this.authenticateHeaderValue = AuthSchemes.NTLM.id + " " + type2Message; this.authenticateHeaderValue = StandardAuthScheme.NTLM + " " + type2Message;
} }
@Override @Override
@ -104,7 +104,7 @@ public class TestClientAuthenticationFakeNTLM extends LocalServerTestBase {
response.setCode(HttpStatus.SC_UNAUTHORIZED); response.setCode(HttpStatus.SC_UNAUTHORIZED);
response.setHeader("Connection", "Keep-Alive"); response.setHeader("Connection", "Keep-Alive");
if (!request.containsHeader(HttpHeaders.AUTHORIZATION)) { if (!request.containsHeader(HttpHeaders.AUTHORIZATION)) {
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.NTLM.id); response.setHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.NTLM);
} else { } else {
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, authenticateHeaderValue); response.setHeader(HttpHeaders.WWW_AUTHENTICATE, authenticateHeaderValue);
} }
@ -164,7 +164,7 @@ public class TestClientAuthenticationFakeNTLM extends LocalServerTestBase {
private final String authenticateHeaderValue; private final String authenticateHeaderValue;
public NtlmType2MessageOnlyResponseHandler(final String type2Message) { public NtlmType2MessageOnlyResponseHandler(final String type2Message) {
this.authenticateHeaderValue = AuthSchemes.NTLM.id + " " + type2Message; this.authenticateHeaderValue = StandardAuthScheme.NTLM + " " + type2Message;
} }
@Override @Override

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.Credentials;
import org.apache.hc.client5.http.auth.KerberosConfig; import org.apache.hc.client5.http.auth.KerberosConfig;
import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider; 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.auth.SPNegoScheme;
import org.apache.hc.client5.http.impl.classic.HttpClients; import org.apache.hc.client5.http.impl.classic.HttpClients;
@ -78,7 +78,7 @@ public class TestSPNegoScheme extends LocalServerTestBase {
final ClassicHttpResponse response, final ClassicHttpResponse response,
final HttpContext context) throws HttpException, IOException { final HttpContext context) throws HttpException, IOException {
response.setCode(HttpStatus.SC_UNAUTHORIZED); response.setCode(HttpStatus.SC_UNAUTHORIZED);
response.addHeader(new BasicHeader("WWW-Authenticate", AuthSchemes.SPNEGO.id + " blablabla")); response.addHeader(new BasicHeader("WWW-Authenticate", StandardAuthScheme.SPNEGO + " blablabla"));
response.addHeader(new BasicHeader("Connection", "Keep-Alive")); response.addHeader(new BasicHeader("Connection", "Keep-Alive"));
response.setEntity(new StringEntity("auth required ")); response.setEntity(new StringEntity("auth required "));
} }
@ -160,7 +160,7 @@ public class TestSPNegoScheme extends LocalServerTestBase {
credentialsProvider.setCredentials(new AuthScope(null, null, -1, null, null), use_jaas_creds); credentialsProvider.setCredentials(new AuthScope(null, null, -1, null, null), use_jaas_creds);
final Registry<AuthSchemeFactory> authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create() final Registry<AuthSchemeFactory> authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create()
.register(AuthSchemes.SPNEGO.id, nsf) .register(StandardAuthScheme.SPNEGO, nsf)
.build(); .build();
this.httpclient = HttpClients.custom() this.httpclient = HttpClients.custom()
.setDefaultAuthSchemeRegistry(authSchemeRegistry) .setDefaultAuthSchemeRegistry(authSchemeRegistry)
@ -191,7 +191,7 @@ public class TestSPNegoScheme extends LocalServerTestBase {
credentialsProvider.setCredentials(new AuthScope(null, null, -1, null, null), use_jaas_creds); credentialsProvider.setCredentials(new AuthScope(null, null, -1, null, null), use_jaas_creds);
final Registry<AuthSchemeFactory> authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create() final Registry<AuthSchemeFactory> authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create()
.register(AuthSchemes.SPNEGO.id, nsf) .register(StandardAuthScheme.SPNEGO, nsf)
.build(); .build();
this.httpclient = HttpClients.custom() this.httpclient = HttpClients.custom()
.setDefaultAuthSchemeRegistry(authSchemeRegistry) .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.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemeFactory; import org.apache.hc.client5.http.auth.AuthSchemeFactory;
import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; 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.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
@ -65,7 +65,7 @@ public class TestWindowsNegotiateScheme extends LocalServerTestBase {
final ClassicHttpRequest request, final ClassicHttpRequest request,
final ClassicHttpResponse response, final ClassicHttpResponse response,
final HttpContext context) throws HttpException, IOException { final HttpContext context) throws HttpException, IOException {
response.addHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.SPNEGO); response.addHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.SPNEGO);
response.setCode(HttpStatus.SC_UNAUTHORIZED); response.setCode(HttpStatus.SC_UNAUTHORIZED);
} }
@ -81,10 +81,10 @@ public class TestWindowsNegotiateScheme extends LocalServerTestBase {
// you can contact the server that authenticated you." is associated with SEC_E_DOWNGRADE_DETECTED. // you can contact the server that authenticated you." is associated with SEC_E_DOWNGRADE_DETECTED.
final Registry<AuthSchemeFactory> authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create() final Registry<AuthSchemeFactory> authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create()
.register(AuthSchemes.SPNEGO.id, new AuthSchemeFactory() { .register(StandardAuthScheme.SPNEGO, new AuthSchemeFactory() {
@Override @Override
public AuthScheme create(final HttpContext context) { public AuthScheme create(final HttpContext context) {
return new WindowsNegotiateSchemeGetTokenFail(AuthSchemes.SPNEGO.id, "HTTP/example.com"); return new WindowsNegotiateSchemeGetTokenFail(StandardAuthScheme.SPNEGO, "HTTP/example.com");
} }
}).build(); }).build();
final CloseableHttpClient customClient = HttpClientBuilder.create() final CloseableHttpClient customClient = HttpClientBuilder.create()

View File

@ -29,7 +29,7 @@ package org.apache.hc.client5.http.impl.win;
import java.util.Locale; import java.util.Locale;
import org.apache.hc.client5.http.auth.AuthSchemeFactory; import org.apache.hc.client5.http.auth.AuthSchemeFactory;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.impl.auth.BasicSchemeFactory; 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.auth.DigestSchemeFactory;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
@ -67,10 +67,10 @@ public class WinHttpClients {
private static HttpClientBuilder createBuilder() { private static HttpClientBuilder createBuilder() {
if (isWinAuthAvailable()) { if (isWinAuthAvailable()) {
final Registry<AuthSchemeFactory> authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create() final Registry<AuthSchemeFactory> authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create()
.register(AuthSchemes.BASIC.id, BasicSchemeFactory.INSTANCE) .register(StandardAuthScheme.BASIC, BasicSchemeFactory.INSTANCE)
.register(AuthSchemes.DIGEST.id, DigestSchemeFactory.INSTANCE) .register(StandardAuthScheme.DIGEST, DigestSchemeFactory.INSTANCE)
.register(AuthSchemes.NTLM.id, WindowsNTLMSchemeFactory.DEFAULT) .register(StandardAuthScheme.NTLM, WindowsNTLMSchemeFactory.DEFAULT)
.register(AuthSchemes.SPNEGO.id, WindowsNegotiateSchemeFactory.DEFAULT) .register(StandardAuthScheme.SPNEGO, WindowsNegotiateSchemeFactory.DEFAULT)
.build(); .build();
return HttpClientBuilder.create() return HttpClientBuilder.create()
.setDefaultAuthSchemeRegistry(authSchemeRegistry); .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.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemeFactory; import org.apache.hc.client5.http.auth.AuthSchemeFactory;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.Experimental; import org.apache.hc.core5.annotation.Experimental;
import org.apache.hc.core5.annotation.ThreadingBehavior; import org.apache.hc.core5.annotation.ThreadingBehavior;
@ -59,7 +59,7 @@ public class WindowsNTLMSchemeFactory implements AuthSchemeFactory {
@Override @Override
public AuthScheme create(final HttpContext context) { public AuthScheme create(final HttpContext context) {
return new WindowsNegotiateScheme(AuthSchemes.NTLM.id, servicePrincipalName); return new WindowsNegotiateScheme(StandardAuthScheme.NTLM, servicePrincipalName);
} }
} }

View File

@ -32,7 +32,7 @@ import org.apache.commons.codec.binary.Base64;
import org.apache.hc.client5.http.RouteInfo; import org.apache.hc.client5.http.RouteInfo;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthScheme; import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthenticationException; import org.apache.hc.client5.http.auth.AuthenticationException;
import org.apache.hc.client5.http.auth.BasicUserPrincipal; import org.apache.hc.client5.http.auth.BasicUserPrincipal;
import org.apache.hc.client5.http.auth.ChallengeType; import org.apache.hc.client5.http.auth.ChallengeType;
@ -86,7 +86,7 @@ public class WindowsNegotiateScheme implements AuthScheme {
WindowsNegotiateScheme(final String scheme, final String servicePrincipalName) { WindowsNegotiateScheme(final String scheme, final String servicePrincipalName) {
super(); super();
this.scheme = (scheme == null) ? AuthSchemes.SPNEGO.id : scheme; this.scheme = (scheme == null) ? StandardAuthScheme.SPNEGO : scheme;
this.continueNeeded = true; this.continueNeeded = true;
this.servicePrincipalName = servicePrincipalName; 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.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemeFactory; import org.apache.hc.client5.http.auth.AuthSchemeFactory;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.Experimental; import org.apache.hc.core5.annotation.Experimental;
import org.apache.hc.core5.annotation.ThreadingBehavior; import org.apache.hc.core5.annotation.ThreadingBehavior;
@ -59,7 +59,7 @@ public class WindowsNegotiateSchemeFactory implements AuthSchemeFactory {
@Override @Override
public AuthScheme create(final HttpContext context) { public AuthScheme create(final HttpContext context) {
return new WindowsNegotiateScheme(AuthSchemes.SPNEGO.id, servicePrincipalName); return new WindowsNegotiateScheme(StandardAuthScheme.SPNEGO, servicePrincipalName);
} }
} }

View File

@ -28,47 +28,45 @@
package org.apache.hc.client5.http.auth; package org.apache.hc.client5.http.auth;
/** /**
* Supported authentication schemes. * Authentication schemes by their names supported by the HttpClient.
* *
* @since 4.3 * @since 4.3
*/ */
public enum AuthSchemes { public final class StandardAuthScheme {
private StandardAuthScheme() {
// no instances
}
/** /**
* Basic authentication scheme as defined in RFC 2617 (considered inherently * Basic authentication scheme as defined in RFC 2617 (considered inherently
* insecure, but most widely supported). * insecure without transport encryption, but most widely supported).
*/ */
BASIC("Basic"), public static final String BASIC = "Basic";
/** /**
* Digest authentication scheme as defined in RFC 2617. * Digest authentication scheme as defined in RFC 2617.
*/ */
DIGEST("Digest"), public static final String DIGEST = "Digest";
/** /**
* The NTLM authentication scheme is a proprietary Microsoft Windows * The NTLM authentication scheme is a proprietary Microsoft Windows
* authentication protocol as defined in [MS-NLMP]. * authentication protocol as defined in [MS-NLMP].
*/ */
NTLM("NTLM"), public static final String NTLM = "NTLM";
/** /**
* SPNEGO authentication scheme as defined in RFC 4559 and RFC 4178 * SPNEGO authentication scheme as defined in RFC 4559 and RFC 4178
* (considered to be the most secure among currently supported * (considered to be the most secure among currently supported
* authentication schemes if Kerberos is selected). * authentication schemes if Kerberos is selected).
*/ */
SPNEGO("Negotiate"), public static final String SPNEGO = "Negotiate";
/** /**
* Kerberos authentication scheme as defined in RFC 4120 * Kerberos authentication scheme as defined in RFC 4120
* (considered to be the most secure among currently supported * (considered to be the most secure among currently supported
* authentication schemes). * authentication schemes).
*/ */
KERBEROS("Kerberos"); public static final String KERBEROS = "Kerberos";
public final String id; }
AuthSchemes(final String id) {
this.id = id;
}
}

View File

@ -28,7 +28,7 @@
package org.apache.hc.client5.http.impl; package org.apache.hc.client5.http.impl;
import org.apache.hc.client5.http.HttpRoute; import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.CredentialsStore; import org.apache.hc.client5.http.auth.CredentialsStore;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
@ -63,7 +63,7 @@ public class AuthSupport {
final char[] password = atColon >= 0 ? userInfo.substring(atColon + 1).toCharArray() : null; final char[] password = atColon >= 0 ? userInfo.substring(atColon + 1).toCharArray() : null;
credentialsStore.setCredentials( credentialsStore.setCredentials(
new AuthScope(scheme, authority.getHostName(), authority.getPort(), null, AuthSchemes.BASIC.id), new AuthScope(scheme, authority.getHostName(), authority.getPort(), null, StandardAuthScheme.BASIC),
new UsernamePasswordCredentials(userName, password)); new UsernamePasswordCredentials(userName, password));
} }

View File

@ -39,7 +39,7 @@ import org.apache.hc.client5.http.AuthenticationStrategy;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthScheme; import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemeFactory; import org.apache.hc.client5.http.auth.AuthSchemeFactory;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.ChallengeType; import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.client5.http.protocol.HttpClientContext;
@ -65,11 +65,11 @@ public class DefaultAuthenticationStrategy implements AuthenticationStrategy {
private static final List<String> DEFAULT_SCHEME_PRIORITY = private static final List<String> DEFAULT_SCHEME_PRIORITY =
Collections.unmodifiableList(Arrays.asList( Collections.unmodifiableList(Arrays.asList(
AuthSchemes.SPNEGO.id, StandardAuthScheme.SPNEGO,
AuthSchemes.KERBEROS.id, StandardAuthScheme.KERBEROS,
AuthSchemes.NTLM.id, StandardAuthScheme.NTLM,
AuthSchemes.DIGEST.id, StandardAuthScheme.DIGEST,
AuthSchemes.BASIC.id)); StandardAuthScheme.BASIC));
@Override @Override
public List<AuthScheme> select( public List<AuthScheme> select(

View File

@ -44,7 +44,7 @@ import org.apache.hc.client5.http.HttpRequestRetryStrategy;
import org.apache.hc.client5.http.SchemePortResolver; import org.apache.hc.client5.http.SchemePortResolver;
import org.apache.hc.client5.http.async.AsyncExecChainHandler; import org.apache.hc.client5.http.async.AsyncExecChainHandler;
import org.apache.hc.client5.http.auth.AuthSchemeFactory; import org.apache.hc.client5.http.auth.AuthSchemeFactory;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.CredentialsProvider; import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.BasicCookieStore; import org.apache.hc.client5.http.cookie.BasicCookieStore;
@ -761,11 +761,11 @@ public class H2AsyncClientBuilder {
Lookup<AuthSchemeFactory> authSchemeRegistryCopy = this.authSchemeRegistry; Lookup<AuthSchemeFactory> authSchemeRegistryCopy = this.authSchemeRegistry;
if (authSchemeRegistryCopy == null) { if (authSchemeRegistryCopy == null) {
authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeFactory>create() authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeFactory>create()
.register(AuthSchemes.BASIC.id, BasicSchemeFactory.INSTANCE) .register(StandardAuthScheme.BASIC, BasicSchemeFactory.INSTANCE)
.register(AuthSchemes.DIGEST.id, DigestSchemeFactory.INSTANCE) .register(StandardAuthScheme.DIGEST, DigestSchemeFactory.INSTANCE)
.register(AuthSchemes.NTLM.id, NTLMSchemeFactory.INSTANCE) .register(StandardAuthScheme.NTLM, NTLMSchemeFactory.INSTANCE)
.register(AuthSchemes.SPNEGO.id, SPNegoSchemeFactory.DEFAULT) .register(StandardAuthScheme.SPNEGO, SPNegoSchemeFactory.DEFAULT)
.register(AuthSchemes.KERBEROS.id, KerberosSchemeFactory.DEFAULT) .register(StandardAuthScheme.KERBEROS, KerberosSchemeFactory.DEFAULT)
.build(); .build();
} }
Lookup<CookieSpecFactory> cookieSpecRegistryCopy = this.cookieSpecRegistry; Lookup<CookieSpecFactory> cookieSpecRegistryCopy = this.cookieSpecRegistry;

View File

@ -45,7 +45,7 @@ import org.apache.hc.client5.http.SchemePortResolver;
import org.apache.hc.client5.http.UserTokenHandler; import org.apache.hc.client5.http.UserTokenHandler;
import org.apache.hc.client5.http.async.AsyncExecChainHandler; import org.apache.hc.client5.http.async.AsyncExecChainHandler;
import org.apache.hc.client5.http.auth.AuthSchemeFactory; import org.apache.hc.client5.http.auth.AuthSchemeFactory;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.CredentialsProvider; import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.BasicCookieStore; import org.apache.hc.client5.http.cookie.BasicCookieStore;
@ -968,11 +968,11 @@ public class HttpAsyncClientBuilder {
Lookup<AuthSchemeFactory> authSchemeRegistryCopy = this.authSchemeRegistry; Lookup<AuthSchemeFactory> authSchemeRegistryCopy = this.authSchemeRegistry;
if (authSchemeRegistryCopy == null) { if (authSchemeRegistryCopy == null) {
authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeFactory>create() authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeFactory>create()
.register(AuthSchemes.BASIC.id, BasicSchemeFactory.INSTANCE) .register(StandardAuthScheme.BASIC, BasicSchemeFactory.INSTANCE)
.register(AuthSchemes.DIGEST.id, DigestSchemeFactory.INSTANCE) .register(StandardAuthScheme.DIGEST, DigestSchemeFactory.INSTANCE)
.register(AuthSchemes.NTLM.id, NTLMSchemeFactory.INSTANCE) .register(StandardAuthScheme.NTLM, NTLMSchemeFactory.INSTANCE)
.register(AuthSchemes.SPNEGO.id, SPNegoSchemeFactory.DEFAULT) .register(StandardAuthScheme.SPNEGO, SPNegoSchemeFactory.DEFAULT)
.register(AuthSchemes.KERBEROS.id, KerberosSchemeFactory.DEFAULT) .register(StandardAuthScheme.KERBEROS, KerberosSchemeFactory.DEFAULT)
.build(); .build();
} }
Lookup<CookieSpecFactory> cookieSpecRegistryCopy = this.cookieSpecRegistry; Lookup<CookieSpecFactory> cookieSpecRegistryCopy = this.cookieSpecRegistry;

View File

@ -42,7 +42,7 @@ import java.util.Map;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthScheme; import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.AuthStateCacheable; import org.apache.hc.client5.http.auth.AuthStateCacheable;
import org.apache.hc.client5.http.auth.AuthenticationException; import org.apache.hc.client5.http.auth.AuthenticationException;
@ -100,7 +100,7 @@ public class BasicScheme implements AuthScheme, Serializable {
@Override @Override
public String getName() { public String getName() {
return AuthSchemes.BASIC.id; return StandardAuthScheme.BASIC;
} }
@Override @Override
@ -174,7 +174,7 @@ public class BasicScheme implements AuthScheme, Serializable {
} }
final byte[] encodedCreds = this.base64codec.encode(this.buffer.toByteArray()); final byte[] encodedCreds = this.base64codec.encode(this.buffer.toByteArray());
this.buffer.reset(); this.buffer.reset();
return AuthSchemes.BASIC.id + " " + new String(encodedCreds, 0, encodedCreds.length, StandardCharsets.US_ASCII); return StandardAuthScheme.BASIC + " " + new String(encodedCreds, 0, encodedCreds.length, StandardCharsets.US_ASCII);
} }
private void writeObject(final ObjectOutputStream out) throws IOException { private void writeObject(final ObjectOutputStream out) throws IOException {

View File

@ -46,7 +46,7 @@ import java.util.StringTokenizer;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthScheme; import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.AuthenticationException; import org.apache.hc.client5.http.auth.AuthenticationException;
import org.apache.hc.client5.http.utils.ByteArrayBuilder; import org.apache.hc.client5.http.utils.ByteArrayBuilder;
@ -127,7 +127,7 @@ public class DigestScheme implements AuthScheme, Serializable {
@Override @Override
public String getName() { public String getName() {
return AuthSchemes.DIGEST.id; return StandardAuthScheme.DIGEST;
} }
@Override @Override
@ -375,7 +375,7 @@ public class DigestScheme implements AuthScheme, Serializable {
final String digest = formatHex(digester.digest(digestInput)); final String digest = formatHex(digester.digest(digestInput));
final CharArrayBuffer buffer = new CharArrayBuffer(128); final CharArrayBuffer buffer = new CharArrayBuffer(128);
buffer.append(AuthSchemes.DIGEST.id + " "); buffer.append(StandardAuthScheme.DIGEST + " ");
final List<BasicNameValuePair> params = new ArrayList<>(20); final List<BasicNameValuePair> params = new ArrayList<>(20);
params.add(new BasicNameValuePair("username", username)); params.add(new BasicNameValuePair("username", username));

View File

@ -35,7 +35,7 @@ import org.apache.hc.client5.http.DnsResolver;
import org.apache.hc.client5.http.SystemDefaultDnsResolver; import org.apache.hc.client5.http.SystemDefaultDnsResolver;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthScheme; import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.AuthenticationException; import org.apache.hc.client5.http.auth.AuthenticationException;
import org.apache.hc.client5.http.auth.Credentials; import org.apache.hc.client5.http.auth.Credentials;
@ -247,7 +247,7 @@ public abstract class GGSSchemeBase implements AuthScheme {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Sending response '" + tokenstr + "' back to the auth server"); log.debug("Sending response '" + tokenstr + "' back to the auth server");
} }
return AuthSchemes.SPNEGO.id + " " + tokenstr; return StandardAuthScheme.SPNEGO + " " + tokenstr;
default: default:
throw new IllegalStateException("Illegal state: " + state); throw new IllegalStateException("Illegal state: " + state);
} }

View File

@ -27,7 +27,7 @@
package org.apache.hc.client5.http.impl.auth; package org.apache.hc.client5.http.impl.auth;
import org.apache.hc.client5.http.DnsResolver; import org.apache.hc.client5.http.DnsResolver;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.KerberosConfig; import org.apache.hc.client5.http.auth.KerberosConfig;
import org.apache.hc.core5.annotation.Experimental; import org.apache.hc.core5.annotation.Experimental;
import org.ietf.jgss.GSSException; import org.ietf.jgss.GSSException;
@ -60,7 +60,7 @@ public class KerberosScheme extends GGSSchemeBase {
@Override @Override
public String getName() { public String getName() {
return AuthSchemes.KERBEROS.id; return StandardAuthScheme.KERBEROS;
} }
@Override @Override

View File

@ -30,7 +30,7 @@ import java.security.Principal;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthScheme; import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.AuthenticationException; import org.apache.hc.client5.http.auth.AuthenticationException;
import org.apache.hc.client5.http.auth.Credentials; import org.apache.hc.client5.http.auth.Credentials;
@ -81,7 +81,7 @@ public final class NTLMScheme implements AuthScheme {
@Override @Override
public String getName() { public String getName() {
return AuthSchemes.NTLM.id; return StandardAuthScheme.NTLM;
} }
@Override @Override
@ -169,7 +169,7 @@ public final class NTLMScheme implements AuthScheme {
} else { } else {
throw new AuthenticationException("Unexpected state: " + this.state); throw new AuthenticationException("Unexpected state: " + this.state);
} }
return AuthSchemes.NTLM.id + " " + response; return StandardAuthScheme.NTLM + " " + response;
} }
@Override @Override

View File

@ -27,7 +27,7 @@
package org.apache.hc.client5.http.impl.auth; package org.apache.hc.client5.http.impl.auth;
import org.apache.hc.client5.http.DnsResolver; import org.apache.hc.client5.http.DnsResolver;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.KerberosConfig; import org.apache.hc.client5.http.auth.KerberosConfig;
import org.apache.hc.core5.annotation.Experimental; import org.apache.hc.core5.annotation.Experimental;
import org.ietf.jgss.GSSException; import org.ietf.jgss.GSSException;
@ -61,7 +61,7 @@ public class SPNegoScheme extends GGSSchemeBase {
@Override @Override
public String getName() { public String getName() {
return AuthSchemes.SPNEGO.id; return StandardAuthScheme.SPNEGO;
} }
@Override @Override

View File

@ -32,15 +32,13 @@ import java.net.PasswordAuthentication;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.Credentials; import org.apache.hc.client5.http.auth.Credentials;
import org.apache.hc.client5.http.auth.CredentialsStore; import org.apache.hc.client5.http.auth.CredentialsStore;
import org.apache.hc.client5.http.auth.NTCredentials; import org.apache.hc.client5.http.auth.NTCredentials;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior; import org.apache.hc.core5.annotation.ThreadingBehavior;
@ -58,25 +56,6 @@ import org.apache.hc.core5.util.Args;
@Contract(threading = ThreadingBehavior.SAFE) @Contract(threading = ThreadingBehavior.SAFE)
public class SystemDefaultCredentialsProvider implements CredentialsStore { public class SystemDefaultCredentialsProvider implements CredentialsStore {
private static final Map<String, String> SCHEME_MAP;
static {
SCHEME_MAP = new ConcurrentHashMap<>();
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) {
if (key == null) {
return null;
}
final String s = SCHEME_MAP.get(key);
return s != null ? s : key;
}
private final BasicCredentialsProvider internal; private final BasicCredentialsProvider internal;
/** /**
@ -112,7 +91,7 @@ public class SystemDefaultCredentialsProvider implements CredentialsStore {
authScope.getPort(), authScope.getPort(),
protocol, protocol,
authScope.getRealm(), authScope.getRealm(),
translateAuthScheme(authScope.getAuthScheme()), authScope.getAuthScheme(),
targetHostURL, targetHostURL,
requestorType); requestorType);
} }
@ -149,7 +128,7 @@ public class SystemDefaultCredentialsProvider implements CredentialsStore {
if (domain != null) { if (domain != null) {
return new NTCredentials(systemcreds.getUserName(), systemcreds.getPassword(), null, domain); return new NTCredentials(systemcreds.getUserName(), systemcreds.getPassword(), null, domain);
} }
if (AuthSchemes.NTLM.id.equalsIgnoreCase(authScope.getAuthScheme())) { if (StandardAuthScheme.NTLM.equalsIgnoreCase(authScope.getAuthScheme())) {
// Domain may be specified in a fully qualified user name // Domain may be specified in a fully qualified user name
return new NTCredentials( return new NTCredentials(
systemcreds.getUserName(), systemcreds.getPassword(), null, null); systemcreds.getUserName(), systemcreds.getPassword(), null, null);

View File

@ -43,7 +43,7 @@ import org.apache.hc.client5.http.HttpRequestRetryStrategy;
import org.apache.hc.client5.http.SchemePortResolver; import org.apache.hc.client5.http.SchemePortResolver;
import org.apache.hc.client5.http.UserTokenHandler; import org.apache.hc.client5.http.UserTokenHandler;
import org.apache.hc.client5.http.auth.AuthSchemeFactory; import org.apache.hc.client5.http.auth.AuthSchemeFactory;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.CredentialsProvider; import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.classic.BackoffManager; import org.apache.hc.client5.http.classic.BackoffManager;
import org.apache.hc.client5.http.classic.ConnectionBackoffStrategy; import org.apache.hc.client5.http.classic.ConnectionBackoffStrategy;
@ -940,11 +940,11 @@ public class HttpClientBuilder {
Lookup<AuthSchemeFactory> authSchemeRegistryCopy = this.authSchemeRegistry; Lookup<AuthSchemeFactory> authSchemeRegistryCopy = this.authSchemeRegistry;
if (authSchemeRegistryCopy == null) { if (authSchemeRegistryCopy == null) {
authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeFactory>create() authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeFactory>create()
.register(AuthSchemes.BASIC.id, BasicSchemeFactory.INSTANCE) .register(StandardAuthScheme.BASIC, BasicSchemeFactory.INSTANCE)
.register(AuthSchemes.DIGEST.id, DigestSchemeFactory.INSTANCE) .register(StandardAuthScheme.DIGEST, DigestSchemeFactory.INSTANCE)
.register(AuthSchemes.NTLM.id, NTLMSchemeFactory.INSTANCE) .register(StandardAuthScheme.NTLM, NTLMSchemeFactory.INSTANCE)
.register(AuthSchemes.SPNEGO.id, SPNegoSchemeFactory.DEFAULT) .register(StandardAuthScheme.SPNEGO, SPNegoSchemeFactory.DEFAULT)
.register(AuthSchemes.KERBEROS.id, KerberosSchemeFactory.DEFAULT) .register(StandardAuthScheme.KERBEROS, KerberosSchemeFactory.DEFAULT)
.build(); .build();
} }
Lookup<CookieSpecFactory> cookieSpecRegistryCopy = this.cookieSpecRegistry; Lookup<CookieSpecFactory> cookieSpecRegistryCopy = this.cookieSpecRegistry;

View File

@ -36,7 +36,7 @@ import org.apache.hc.client5.http.RouteInfo.LayerType;
import org.apache.hc.client5.http.RouteInfo.TunnelType; import org.apache.hc.client5.http.RouteInfo.TunnelType;
import org.apache.hc.client5.http.auth.AuthExchange; import org.apache.hc.client5.http.auth.AuthExchange;
import org.apache.hc.client5.http.auth.AuthSchemeFactory; import org.apache.hc.client5.http.auth.AuthSchemeFactory;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.ChallengeType; import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.auth.Credentials; import org.apache.hc.client5.http.auth.Credentials;
@ -113,11 +113,11 @@ public class ProxyClient {
this.authenticator = new HttpAuthenticator(); this.authenticator = new HttpAuthenticator();
this.proxyAuthExchange = new AuthExchange(); this.proxyAuthExchange = new AuthExchange();
this.authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create() this.authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create()
.register(AuthSchemes.BASIC.id, BasicSchemeFactory.INSTANCE) .register(StandardAuthScheme.BASIC, BasicSchemeFactory.INSTANCE)
.register(AuthSchemes.DIGEST.id, DigestSchemeFactory.INSTANCE) .register(StandardAuthScheme.DIGEST, DigestSchemeFactory.INSTANCE)
.register(AuthSchemes.NTLM.id, NTLMSchemeFactory.INSTANCE) .register(StandardAuthScheme.NTLM, NTLMSchemeFactory.INSTANCE)
.register(AuthSchemes.SPNEGO.id, SPNegoSchemeFactory.DEFAULT) .register(StandardAuthScheme.SPNEGO, SPNegoSchemeFactory.DEFAULT)
.register(AuthSchemes.KERBEROS.id, KerberosSchemeFactory.DEFAULT) .register(StandardAuthScheme.KERBEROS, KerberosSchemeFactory.DEFAULT)
.build(); .build();
this.reuseStrategy = new DefaultConnectionReuseStrategy(); this.reuseStrategy = new DefaultConnectionReuseStrategy();
} }

View File

@ -37,21 +37,21 @@ public class TestAuthChallenge {
@Test @Test
public void testAuthChallengeWithValue() { public void testAuthChallengeWithValue() {
final AuthChallenge authChallenge = new AuthChallenge(ChallengeType.TARGET, AuthSchemes.BASIC.id, "blah", null); final AuthChallenge authChallenge = new AuthChallenge(ChallengeType.TARGET, StandardAuthScheme.BASIC, "blah", null);
Assert.assertEquals(AuthSchemes.BASIC.id, authChallenge.getScheme()); Assert.assertEquals(StandardAuthScheme.BASIC, authChallenge.getScheme());
Assert.assertEquals("blah", authChallenge.getValue()); Assert.assertEquals("blah", authChallenge.getValue());
Assert.assertEquals(null, authChallenge.getParams()); Assert.assertEquals(null, authChallenge.getParams());
Assert.assertEquals(AuthSchemes.BASIC.id + " blah", authChallenge.toString()); Assert.assertEquals(StandardAuthScheme.BASIC + " blah", authChallenge.toString());
} }
@Test @Test
public void testAuthChallengeWithParams() { public void testAuthChallengeWithParams() {
final AuthChallenge authChallenge = new AuthChallenge(ChallengeType.TARGET, AuthSchemes.BASIC.id, null, final AuthChallenge authChallenge = new AuthChallenge(ChallengeType.TARGET, StandardAuthScheme.BASIC, null,
Arrays.asList(new BasicNameValuePair("blah", "this"), new BasicNameValuePair("blah", "that"))); Arrays.asList(new BasicNameValuePair("blah", "this"), new BasicNameValuePair("blah", "that")));
Assert.assertEquals(AuthSchemes.BASIC.id, authChallenge.getScheme()); Assert.assertEquals(StandardAuthScheme.BASIC, authChallenge.getScheme());
Assert.assertEquals(null, authChallenge.getValue()); Assert.assertEquals(null, authChallenge.getValue());
Assert.assertNotNull(authChallenge.getParams()); Assert.assertNotNull(authChallenge.getParams());
Assert.assertEquals(AuthSchemes.BASIC.id + " [blah=this, blah=that]", authChallenge.toString()); Assert.assertEquals(StandardAuthScheme.BASIC + " [blah=this, blah=that]", authChallenge.toString());
} }
} }

View File

@ -30,7 +30,7 @@ package org.apache.hc.client5.http.config;
import java.util.Collections; import java.util.Collections;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.cookie.CookieSpecs; import org.apache.hc.client5.http.cookie.CookieSpecs;
import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.util.TimeValue; import org.apache.hc.core5.util.TimeValue;
@ -75,8 +75,8 @@ public class TestRequestConfig {
.setMaxRedirects(100) .setMaxRedirects(100)
.setCookieSpec(CookieSpecs.STANDARD.id) .setCookieSpec(CookieSpecs.STANDARD.id)
.setProxy(new HttpHost("someproxy")) .setProxy(new HttpHost("someproxy"))
.setTargetPreferredAuthSchemes(Collections.singletonList(AuthSchemes.NTLM.id)) .setTargetPreferredAuthSchemes(Collections.singletonList(StandardAuthScheme.NTLM))
.setProxyPreferredAuthSchemes(Collections.singletonList(AuthSchemes.DIGEST.id)) .setProxyPreferredAuthSchemes(Collections.singletonList(StandardAuthScheme.DIGEST))
.setContentCompressionEnabled(false) .setContentCompressionEnabled(false)
.build(); .build();
final RequestConfig config = RequestConfig.copy(config0).build(); final RequestConfig config = RequestConfig.copy(config0).build();
@ -89,8 +89,8 @@ public class TestRequestConfig {
Assert.assertEquals(100, config.getMaxRedirects()); Assert.assertEquals(100, config.getMaxRedirects());
Assert.assertEquals(CookieSpecs.STANDARD.id, config.getCookieSpec()); Assert.assertEquals(CookieSpecs.STANDARD.id, config.getCookieSpec());
Assert.assertEquals(new HttpHost("someproxy"), config.getProxy()); Assert.assertEquals(new HttpHost("someproxy"), config.getProxy());
Assert.assertEquals(Collections.singletonList(AuthSchemes.NTLM.id), config.getTargetPreferredAuthSchemes()); Assert.assertEquals(Collections.singletonList(StandardAuthScheme.NTLM), config.getTargetPreferredAuthSchemes());
Assert.assertEquals(Collections.singletonList(AuthSchemes.DIGEST.id), config.getProxyPreferredAuthSchemes()); Assert.assertEquals(Collections.singletonList(StandardAuthScheme.DIGEST), config.getProxyPreferredAuthSchemes());
Assert.assertEquals(false, config.isContentCompressionEnabled()); Assert.assertEquals(false, config.isContentCompressionEnabled());
} }

View File

@ -38,7 +38,7 @@ import javax.net.ssl.SSLContext;
import org.apache.hc.client5.http.DnsResolver; import org.apache.hc.client5.http.DnsResolver;
import org.apache.hc.client5.http.HttpRoute; import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.SystemDefaultDnsResolver; import org.apache.hc.client5.http.SystemDefaultDnsResolver;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.CredentialsProvider; import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.config.RequestConfig;
@ -195,8 +195,8 @@ public class ClientConfiguration {
final RequestConfig defaultRequestConfig = RequestConfig.custom() final RequestConfig defaultRequestConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.STANDARD.id) .setCookieSpec(CookieSpecs.STANDARD.id)
.setExpectContinueEnabled(true) .setExpectContinueEnabled(true)
.setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM.id, AuthSchemes.DIGEST.id)) .setTargetPreferredAuthSchemes(Arrays.asList(StandardAuthScheme.NTLM, StandardAuthScheme.DIGEST))
.setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC.id)) .setProxyPreferredAuthSchemes(Arrays.asList(StandardAuthScheme.BASIC))
.build(); .build();
// Create an HttpClient with the given custom dependencies and configuration. // Create an HttpClient with the given custom dependencies and configuration.

View File

@ -38,7 +38,7 @@ import org.apache.hc.client5.http.auth.AuthSchemeFactory;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.ChallengeType; import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.config.RequestConfig; 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.BasicCredentialsProvider;
import org.apache.hc.client5.http.impl.auth.BasicScheme; import org.apache.hc.client5.http.impl.auth.BasicScheme;
@ -85,9 +85,9 @@ public class TestAuthenticationStrategy {
final HttpClientContext context = HttpClientContext.create(); final HttpClientContext context = HttpClientContext.create();
final Map<String, AuthChallenge> challenges = new HashMap<>(); final Map<String, AuthChallenge> challenges = new HashMap<>();
challenges.put(AuthSchemes.BASIC.id.toLowerCase(Locale.ROOT), new AuthChallenge(ChallengeType.TARGET, AuthSchemes.BASIC.id, challenges.put(StandardAuthScheme.BASIC.toLowerCase(Locale.ROOT), new AuthChallenge(ChallengeType.TARGET, StandardAuthScheme.BASIC,
new BasicNameValuePair("realm", "test"))); new BasicNameValuePair("realm", "test")));
challenges.put(AuthSchemes.DIGEST.id.toLowerCase(Locale.ROOT), new AuthChallenge(ChallengeType.TARGET, AuthSchemes.DIGEST.id, challenges.put(StandardAuthScheme.DIGEST.toLowerCase(Locale.ROOT), new AuthChallenge(ChallengeType.TARGET, StandardAuthScheme.DIGEST,
new BasicNameValuePair("realm", "test"), new BasicNameValuePair("nonce", "1234"))); new BasicNameValuePair("realm", "test"), new BasicNameValuePair("nonce", "1234")));
final List<AuthScheme> authSchemes = authStrategy.select(ChallengeType.TARGET, challenges, context); final List<AuthScheme> authSchemes = authStrategy.select(ChallengeType.TARGET, challenges, context);
@ -101,16 +101,16 @@ public class TestAuthenticationStrategy {
final HttpClientContext context = HttpClientContext.create(); final HttpClientContext context = HttpClientContext.create();
final Map<String, AuthChallenge> challenges = new HashMap<>(); final Map<String, AuthChallenge> challenges = new HashMap<>();
challenges.put(AuthSchemes.BASIC.id.toLowerCase(Locale.ROOT), new AuthChallenge(ChallengeType.TARGET, AuthSchemes.BASIC.id, challenges.put(StandardAuthScheme.BASIC.toLowerCase(Locale.ROOT), new AuthChallenge(ChallengeType.TARGET, StandardAuthScheme.BASIC,
new BasicNameValuePair("realm", "realm1"))); new BasicNameValuePair("realm", "realm1")));
challenges.put(AuthSchemes.DIGEST.id.toLowerCase(Locale.ROOT), new AuthChallenge(ChallengeType.TARGET, AuthSchemes.DIGEST.id, challenges.put(StandardAuthScheme.DIGEST.toLowerCase(Locale.ROOT), new AuthChallenge(ChallengeType.TARGET, StandardAuthScheme.DIGEST,
new BasicNameValuePair("realm", "realm2"), new BasicNameValuePair("nonce", "1234"))); new BasicNameValuePair("realm", "realm2"), new BasicNameValuePair("nonce", "1234")));
challenges.put("whatever", new AuthChallenge(ChallengeType.TARGET, "Whatever", challenges.put("whatever", new AuthChallenge(ChallengeType.TARGET, "Whatever",
new BasicNameValuePair("realm", "realm3"))); new BasicNameValuePair("realm", "realm3")));
final Registry<AuthSchemeFactory> authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create() final Registry<AuthSchemeFactory> authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create()
.register(AuthSchemes.BASIC.id, BasicSchemeFactory.INSTANCE) .register(StandardAuthScheme.BASIC, BasicSchemeFactory.INSTANCE)
.register(AuthSchemes.DIGEST.id, DigestSchemeFactory.INSTANCE).build(); .register(StandardAuthScheme.DIGEST, DigestSchemeFactory.INSTANCE).build();
context.setAuthSchemeRegistry(authSchemeRegistry); context.setAuthSchemeRegistry(authSchemeRegistry);
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
@ -131,20 +131,20 @@ public class TestAuthenticationStrategy {
public void testCustomAuthPreference() throws Exception { public void testCustomAuthPreference() throws Exception {
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy(); final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
final RequestConfig config = RequestConfig.custom() final RequestConfig config = RequestConfig.custom()
.setTargetPreferredAuthSchemes(Collections.singletonList(AuthSchemes.BASIC.id)) .setTargetPreferredAuthSchemes(Collections.singletonList(StandardAuthScheme.BASIC))
.build(); .build();
final HttpClientContext context = HttpClientContext.create(); final HttpClientContext context = HttpClientContext.create();
final Map<String, AuthChallenge> challenges = new HashMap<>(); final Map<String, AuthChallenge> challenges = new HashMap<>();
challenges.put(AuthSchemes.BASIC.id.toLowerCase(Locale.ROOT), new AuthChallenge(ChallengeType.TARGET, AuthSchemes.BASIC.id, challenges.put(StandardAuthScheme.BASIC.toLowerCase(Locale.ROOT), new AuthChallenge(ChallengeType.TARGET, StandardAuthScheme.BASIC,
new BasicNameValuePair("realm", "realm1"))); new BasicNameValuePair("realm", "realm1")));
challenges.put(AuthSchemes.DIGEST.id.toLowerCase(Locale.ROOT), new AuthChallenge(ChallengeType.TARGET, AuthSchemes.DIGEST.id, challenges.put(StandardAuthScheme.DIGEST.toLowerCase(Locale.ROOT), new AuthChallenge(ChallengeType.TARGET, StandardAuthScheme.DIGEST,
new BasicNameValuePair("realm", "realm2"), new BasicNameValuePair("nonce", "1234"))); new BasicNameValuePair("realm", "realm2"), new BasicNameValuePair("nonce", "1234")));
final Registry<AuthSchemeFactory> authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create() final Registry<AuthSchemeFactory> authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create()
.register(AuthSchemes.BASIC.id, BasicSchemeFactory.INSTANCE) .register(StandardAuthScheme.BASIC, BasicSchemeFactory.INSTANCE)
.register(AuthSchemes.DIGEST.id, DigestSchemeFactory.INSTANCE).build(); .register(StandardAuthScheme.DIGEST, DigestSchemeFactory.INSTANCE).build();
context.setAuthSchemeRegistry(authSchemeRegistry); context.setAuthSchemeRegistry(authSchemeRegistry);
context.setRequestConfig(config); context.setRequestConfig(config);

View File

@ -29,7 +29,7 @@ package org.apache.hc.client5.http.impl.auth;
import java.util.List; import java.util.List;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.ChallengeType; import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.core5.http.NameValuePair; import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.http.ParseException; import org.apache.hc.core5.http.ParseException;
@ -151,13 +151,13 @@ public class TestAuthChallengeParser {
@Test @Test
public void testParseBasicAuthChallenge() throws Exception { public void testParseBasicAuthChallenge() throws Exception {
final CharArrayBuffer buffer = new CharArrayBuffer(64); final CharArrayBuffer buffer = new CharArrayBuffer(64);
buffer.append(AuthSchemes.BASIC.id + " realm=blah"); buffer.append(StandardAuthScheme.BASIC + " realm=blah");
final ParserCursor cursor = new ParserCursor(0, buffer.length()); final ParserCursor cursor = new ParserCursor(0, buffer.length());
final List<AuthChallenge> challenges = parser.parse(ChallengeType.TARGET, buffer, cursor); final List<AuthChallenge> challenges = parser.parse(ChallengeType.TARGET, buffer, cursor);
Assert.assertNotNull(challenges); Assert.assertNotNull(challenges);
Assert.assertEquals(1, challenges.size()); Assert.assertEquals(1, challenges.size());
final AuthChallenge challenge1 = challenges.get(0); final AuthChallenge challenge1 = challenges.get(0);
Assert.assertEquals(AuthSchemes.BASIC.id, challenge1.getScheme()); Assert.assertEquals(StandardAuthScheme.BASIC, challenge1.getScheme());
Assert.assertEquals(null, challenge1.getValue()); Assert.assertEquals(null, challenge1.getValue());
final List<NameValuePair> params = challenge1.getParams(); final List<NameValuePair> params = challenge1.getParams();
Assert.assertNotNull(params); Assert.assertNotNull(params);
@ -168,13 +168,13 @@ public class TestAuthChallengeParser {
@Test @Test
public void testParseAuthChallengeWithBlanks() throws Exception { public void testParseAuthChallengeWithBlanks() throws Exception {
final CharArrayBuffer buffer = new CharArrayBuffer(64); final CharArrayBuffer buffer = new CharArrayBuffer(64);
buffer.append(" " + AuthSchemes.BASIC.id + " realm = blah "); buffer.append(" " + StandardAuthScheme.BASIC + " realm = blah ");
final ParserCursor cursor = new ParserCursor(0, buffer.length()); final ParserCursor cursor = new ParserCursor(0, buffer.length());
final List<AuthChallenge> challenges = parser.parse(ChallengeType.TARGET, buffer, cursor); final List<AuthChallenge> challenges = parser.parse(ChallengeType.TARGET, buffer, cursor);
Assert.assertNotNull(challenges); Assert.assertNotNull(challenges);
Assert.assertEquals(1, challenges.size()); Assert.assertEquals(1, challenges.size());
final AuthChallenge challenge1 = challenges.get(0); final AuthChallenge challenge1 = challenges.get(0);
Assert.assertEquals(AuthSchemes.BASIC.id, challenge1.getScheme()); Assert.assertEquals(StandardAuthScheme.BASIC, challenge1.getScheme());
Assert.assertEquals(null, challenge1.getValue()); Assert.assertEquals(null, challenge1.getValue());
final List<NameValuePair> params = challenge1.getParams(); final List<NameValuePair> params = challenge1.getParams();
Assert.assertNotNull(params); Assert.assertNotNull(params);
@ -206,15 +206,15 @@ public class TestAuthChallengeParser {
@Test @Test
public void testParseMultipleAuthChallengeWithParams() throws Exception { public void testParseMultipleAuthChallengeWithParams() throws Exception {
final CharArrayBuffer buffer = new CharArrayBuffer(64); final CharArrayBuffer buffer = new CharArrayBuffer(64);
buffer.append(AuthSchemes.BASIC.id + " realm=blah, param1 = this, param2=that, " + buffer.append(StandardAuthScheme.BASIC + " realm=blah, param1 = this, param2=that, " +
AuthSchemes.BASIC.id + " realm=\"\\\"yada\\\"\", this, that=,this-and-that "); StandardAuthScheme.BASIC + " realm=\"\\\"yada\\\"\", this, that=,this-and-that ");
final ParserCursor cursor = new ParserCursor(0, buffer.length()); final ParserCursor cursor = new ParserCursor(0, buffer.length());
final List<AuthChallenge> challenges = parser.parse(ChallengeType.TARGET, buffer, cursor); final List<AuthChallenge> challenges = parser.parse(ChallengeType.TARGET, buffer, cursor);
Assert.assertNotNull(challenges); Assert.assertNotNull(challenges);
Assert.assertEquals(2, challenges.size()); Assert.assertEquals(2, challenges.size());
final AuthChallenge challenge1 = challenges.get(0); final AuthChallenge challenge1 = challenges.get(0);
Assert.assertEquals(AuthSchemes.BASIC.id, challenge1.getScheme()); Assert.assertEquals(StandardAuthScheme.BASIC, challenge1.getScheme());
Assert.assertEquals(null, challenge1.getValue()); Assert.assertEquals(null, challenge1.getValue());
final List<NameValuePair> params1 = challenge1.getParams(); final List<NameValuePair> params1 = challenge1.getParams();
Assert.assertNotNull(params1); Assert.assertNotNull(params1);
@ -224,7 +224,7 @@ public class TestAuthChallengeParser {
assertNameValuePair(new BasicNameValuePair("param2", "that"), params1.get(2)); assertNameValuePair(new BasicNameValuePair("param2", "that"), params1.get(2));
final AuthChallenge challenge2 = challenges.get(1); final AuthChallenge challenge2 = challenges.get(1);
Assert.assertEquals(AuthSchemes.BASIC.id, challenge2.getScheme()); Assert.assertEquals(StandardAuthScheme.BASIC, challenge2.getScheme());
Assert.assertEquals(null, challenge2.getValue()); Assert.assertEquals(null, challenge2.getValue());
final List<NameValuePair> params2 = challenge2.getParams(); final List<NameValuePair> params2 = challenge2.getParams();
Assert.assertNotNull(params2); Assert.assertNotNull(params2);

View File

@ -26,7 +26,7 @@
*/ */
package org.apache.hc.client5.http.impl.auth; package org.apache.hc.client5.http.impl.auth;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.Credentials; import org.apache.hc.client5.http.auth.Credentials;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
@ -142,15 +142,15 @@ public class TestBasicCredentialsProvider {
state.setCredentials(scope2, creds2); state.setCredentials(scope2, creds2);
state.setCredentials(scope3, creds3); state.setCredentials(scope3, creds3);
Credentials got = state.getCredentials(new AuthScope("http", "someotherhost", 80, "someotherrealm", AuthSchemes.BASIC.id), null); Credentials got = state.getCredentials(new AuthScope("http", "someotherhost", 80, "someotherrealm", StandardAuthScheme.BASIC), null);
Credentials expected = creds1; Credentials expected = creds1;
Assert.assertEquals(expected, got); Assert.assertEquals(expected, got);
got = state.getCredentials(new AuthScope("http", "someotherhost", 80, "somerealm", AuthSchemes.BASIC.id), null); got = state.getCredentials(new AuthScope("http", "someotherhost", 80, "somerealm", StandardAuthScheme.BASIC), null);
expected = creds2; expected = creds2;
Assert.assertEquals(expected, got); Assert.assertEquals(expected, got);
got = state.getCredentials(new AuthScope("http", "somehost", 80, "someotherrealm", AuthSchemes.BASIC.id), null); got = state.getCredentials(new AuthScope("http", "somehost", 80, "someotherrealm", StandardAuthScheme.BASIC), null);
expected = creds3; expected = creds3;
Assert.assertEquals(expected, got); Assert.assertEquals(expected, got);
} }

View File

@ -36,7 +36,7 @@ import java.util.List;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthScheme; import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.ChallengeType; import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
@ -65,7 +65,7 @@ public class TestBasicScheme {
@Test @Test
public void testBasicAuthenticationEmptyChallenge() throws Exception { public void testBasicAuthenticationEmptyChallenge() throws Exception {
final String challenge = AuthSchemes.BASIC.id; final String challenge = StandardAuthScheme.BASIC;
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final AuthScheme authscheme = new BasicScheme(); final AuthScheme authscheme = new BasicScheme();
authscheme.processChallenge(authChallenge, null); authscheme.processChallenge(authChallenge, null);
@ -90,12 +90,12 @@ public class TestBasicScheme {
Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null)); Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
final HttpRequest request = new BasicHttpRequest("GET", "/"); final HttpRequest request = new BasicHttpRequest("GET", "/");
final String authResponse = authscheme.generateAuthResponse(host, request, null); final String authResponse = authscheme.generateAuthResponse(host, request, null);
Assert.assertEquals(AuthSchemes.BASIC.id + " ZGg65C32Lfw=", authResponse); Assert.assertEquals(StandardAuthScheme.BASIC + " ZGg65C32Lfw=", authResponse);
} }
@Test @Test
public void testBasicAuthentication() throws Exception { public void testBasicAuthentication() throws Exception {
final AuthChallenge authChallenge = parse(AuthSchemes.BASIC.id + " realm=\"test\""); final AuthChallenge authChallenge = parse(StandardAuthScheme.BASIC + " realm=\"test\"");
final BasicScheme authscheme = new BasicScheme(); final BasicScheme authscheme = new BasicScheme();
authscheme.processChallenge(authChallenge, null); authscheme.processChallenge(authChallenge, null);
@ -110,7 +110,7 @@ public class TestBasicScheme {
Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null)); Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
final String authResponse = authscheme.generateAuthResponse(host, request, null); final String authResponse = authscheme.generateAuthResponse(host, request, null);
final String expected = AuthSchemes.BASIC.id + " " + new String( final String expected = StandardAuthScheme.BASIC + " " + new String(
Base64.encodeBase64("testuser:testpass".getBytes(StandardCharsets.US_ASCII)), Base64.encodeBase64("testuser:testpass".getBytes(StandardCharsets.US_ASCII)),
StandardCharsets.US_ASCII); StandardCharsets.US_ASCII);
Assert.assertEquals(expected, authResponse); Assert.assertEquals(expected, authResponse);
@ -121,7 +121,7 @@ public class TestBasicScheme {
@Test @Test
public void testBasicProxyAuthentication() throws Exception { public void testBasicProxyAuthentication() throws Exception {
final AuthChallenge authChallenge = parse(AuthSchemes.BASIC.id + " realm=\"test\""); final AuthChallenge authChallenge = parse(StandardAuthScheme.BASIC + " realm=\"test\"");
final BasicScheme authscheme = new BasicScheme(); final BasicScheme authscheme = new BasicScheme();
authscheme.processChallenge(authChallenge, null); authscheme.processChallenge(authChallenge, null);
@ -136,7 +136,7 @@ public class TestBasicScheme {
Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null)); Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
final String authResponse = authscheme.generateAuthResponse(host, request, null); final String authResponse = authscheme.generateAuthResponse(host, request, null);
final String expected = AuthSchemes.BASIC.id + " " + new String( final String expected = StandardAuthScheme.BASIC + " " + new String(
Base64.encodeBase64("testuser:testpass".getBytes(StandardCharsets.US_ASCII)), Base64.encodeBase64("testuser:testpass".getBytes(StandardCharsets.US_ASCII)),
StandardCharsets.US_ASCII); StandardCharsets.US_ASCII);
Assert.assertEquals(expected, authResponse); Assert.assertEquals(expected, authResponse);
@ -147,7 +147,7 @@ public class TestBasicScheme {
@Test @Test
public void testSerialization() throws Exception { public void testSerialization() throws Exception {
final AuthChallenge authChallenge = parse(AuthSchemes.BASIC.id + " realm=\"test\""); final AuthChallenge authChallenge = parse(StandardAuthScheme.BASIC + " realm=\"test\"");
final BasicScheme basicScheme = new BasicScheme(); final BasicScheme basicScheme = new BasicScheme();
basicScheme.processChallenge(authChallenge, null); basicScheme.processChallenge(authChallenge, null);

View File

@ -39,7 +39,7 @@ import java.util.Map;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthScheme; import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.AuthenticationException; import org.apache.hc.client5.http.auth.AuthenticationException;
import org.apache.hc.client5.http.auth.ChallengeType; import org.apache.hc.client5.http.auth.ChallengeType;
@ -78,14 +78,14 @@ public class TestDigestScheme {
@Test(expected=MalformedChallengeException.class) @Test(expected=MalformedChallengeException.class)
public void testDigestAuthenticationEmptyChallenge1() throws Exception { public void testDigestAuthenticationEmptyChallenge1() throws Exception {
final AuthChallenge authChallenge = parse(AuthSchemes.DIGEST.id); final AuthChallenge authChallenge = parse(StandardAuthScheme.DIGEST);
final AuthScheme authscheme = new DigestScheme(); final AuthScheme authscheme = new DigestScheme();
authscheme.processChallenge(authChallenge, null); authscheme.processChallenge(authChallenge, null);
} }
@Test(expected=MalformedChallengeException.class) @Test(expected=MalformedChallengeException.class)
public void testDigestAuthenticationEmptyChallenge2() throws Exception { public void testDigestAuthenticationEmptyChallenge2() throws Exception {
final AuthChallenge authChallenge = parse(AuthSchemes.DIGEST.id + " "); final AuthChallenge authChallenge = parse(StandardAuthScheme.DIGEST + " ");
final AuthScheme authscheme = new DigestScheme(); final AuthScheme authscheme = new DigestScheme();
authscheme.processChallenge(authChallenge, null); authscheme.processChallenge(authChallenge, null);
} }
@ -99,7 +99,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge = AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\""; final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final DigestScheme authscheme = new DigestScheme(); final DigestScheme authscheme = new DigestScheme();
authscheme.processChallenge(authChallenge, null); authscheme.processChallenge(authChallenge, null);
@ -126,7 +126,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge = AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\""; final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final DigestScheme authscheme = new DigestScheme(); final DigestScheme authscheme = new DigestScheme();
authscheme.processChallenge(authChallenge, null); authscheme.processChallenge(authChallenge, null);
@ -150,7 +150,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge = AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\""; final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final DigestScheme authscheme = new DigestScheme(); final DigestScheme authscheme = new DigestScheme();
authscheme.processChallenge(authChallenge, null); authscheme.processChallenge(authChallenge, null);
@ -181,7 +181,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge = AuthSchemes.DIGEST.id + " realm=\"realm1\", " + final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", " +
"nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " + "nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
"algorithm=SHA"; "algorithm=SHA";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
@ -208,7 +208,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge = AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\""; final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final DigestScheme authscheme = new DigestScheme(); final DigestScheme authscheme = new DigestScheme();
authscheme.processChallenge(authChallenge, null); authscheme.processChallenge(authChallenge, null);
@ -233,7 +233,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge = AuthSchemes.DIGEST.id + " no-realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\""; final String challenge = StandardAuthScheme.DIGEST + " no-realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final DigestScheme authscheme = new DigestScheme(); final DigestScheme authscheme = new DigestScheme();
authscheme.processChallenge(authChallenge, null); authscheme.processChallenge(authChallenge, null);
@ -251,7 +251,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge = AuthSchemes.DIGEST.id + " realm=\"realm1\", no-nonce=\"f2a3f18799759d4f1a1c068b92b573cb\""; final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", no-nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final DigestScheme authscheme = new DigestScheme(); final DigestScheme authscheme = new DigestScheme();
authscheme.processChallenge(authChallenge, null); authscheme.processChallenge(authChallenge, null);
@ -279,7 +279,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials(username, password.toCharArray()); final Credentials creds = new UsernamePasswordCredentials(username, password.toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge=AuthSchemes.DIGEST.id + " realm=\"" + realm + "\", " final String challenge=StandardAuthScheme.DIGEST + " realm=\"" + realm + "\", "
+ "nonce=\"" + nonce + "\", " + "nonce=\"" + nonce + "\", "
+ "opaque=\"SomeString\", " + "opaque=\"SomeString\", "
+ "stale=false, " + "stale=false, "
@ -330,7 +330,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials(username, password.toCharArray()); final Credentials creds = new UsernamePasswordCredentials(username, password.toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge=AuthSchemes.DIGEST.id + " realm=\"" + realm + "\", " final String challenge=StandardAuthScheme.DIGEST + " realm=\"" + realm + "\", "
+ "nonce=\"" + nonce + "\", " + "nonce=\"" + nonce + "\", "
+ "opaque=\"SomeString\", " + "opaque=\"SomeString\", "
+ "stale=false, " + "stale=false, "
@ -375,7 +375,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials(username, password.toCharArray()); final Credentials creds = new UsernamePasswordCredentials(username, password.toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge=AuthSchemes.DIGEST.id + " realm=\"" + realm + "\", " final String challenge=StandardAuthScheme.DIGEST + " realm=\"" + realm + "\", "
+ "nonce=\"" + nonce + "\", " + "nonce=\"" + nonce + "\", "
+ "opaque=\"SomeString\", " + "opaque=\"SomeString\", "
+ "stale=false, " + "stale=false, "
@ -410,7 +410,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials(username, password.toCharArray()); final Credentials creds = new UsernamePasswordCredentials(username, password.toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge=AuthSchemes.DIGEST.id + " realm=\"" + realm + "\", " final String challenge=StandardAuthScheme.DIGEST + " realm=\"" + realm + "\", "
+ "nonce=\"" + nonce + "\", " + "nonce=\"" + nonce + "\", "
+ "opaque=\"SomeString\", " + "opaque=\"SomeString\", "
+ "stale=false, " + "stale=false, "
@ -428,7 +428,7 @@ public class TestDigestScheme {
@Test @Test
public void testDigestAuthenticationWithStaleNonce() throws Exception { public void testDigestAuthenticationWithStaleNonce() throws Exception {
final String challenge = AuthSchemes.DIGEST.id + " realm=\"realm1\", " + final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", " +
"nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", stale=\"true\""; "nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", stale=\"true\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final AuthScheme authscheme = new DigestScheme(); final AuthScheme authscheme = new DigestScheme();
@ -438,7 +438,7 @@ public class TestDigestScheme {
} }
private static Map<String, String> parseAuthResponse(final String authResponse) { private static Map<String, String> parseAuthResponse(final String authResponse) {
if (!authResponse.startsWith(AuthSchemes.DIGEST.id + " ")) { if (!authResponse.startsWith(StandardAuthScheme.DIGEST + " ")) {
return null; return null;
} }
final String s = authResponse.substring(7); final String s = authResponse.substring(7);
@ -460,7 +460,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge1 = AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", qop=auth"; final String challenge1 = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", qop=auth";
final AuthChallenge authChallenge1 = parse(challenge1); final AuthChallenge authChallenge1 = parse(challenge1);
final DigestScheme authscheme = new DigestScheme(); final DigestScheme authscheme = new DigestScheme();
@ -476,7 +476,7 @@ public class TestDigestScheme {
final Map<String, String> table2 = parseAuthResponse(authResponse2); final Map<String, String> table2 = parseAuthResponse(authResponse2);
Assert.assertEquals("00000002", table2.get("nc")); Assert.assertEquals("00000002", table2.get("nc"));
final String challenge2 = AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", qop=auth"; final String challenge2 = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", qop=auth";
final AuthChallenge authChallenge2 = parse(challenge2); final AuthChallenge authChallenge2 = parse(challenge2);
authscheme.processChallenge(authChallenge2, null); authscheme.processChallenge(authChallenge2, null);
@ -485,7 +485,7 @@ public class TestDigestScheme {
final Map<String, String> table3 = parseAuthResponse(authResponse3); final Map<String, String> table3 = parseAuthResponse(authResponse3);
Assert.assertEquals("00000003", table3.get("nc")); Assert.assertEquals("00000003", table3.get("nc"));
final String challenge3 = AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"e273f1776275974f1a120d8b92c5b3cb\", qop=auth"; final String challenge3 = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"e273f1776275974f1a120d8b92c5b3cb\", qop=auth";
final AuthChallenge authChallenge3 = parse(challenge3); final AuthChallenge authChallenge3 = parse(challenge3);
authscheme.processChallenge(authChallenge3, null); authscheme.processChallenge(authChallenge3, null);
@ -505,7 +505,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge1 = AuthSchemes.DIGEST.id + " qop=\"auth\", algorithm=MD5-sess, nonce=\"1234567890abcdef\", " + final String challenge1 = StandardAuthScheme.DIGEST + " qop=\"auth\", algorithm=MD5-sess, nonce=\"1234567890abcdef\", " +
"charset=utf-8, realm=\"subnet.domain.com\""; "charset=utf-8, realm=\"subnet.domain.com\"";
final AuthChallenge authChallenge1 = parse(challenge1); final AuthChallenge authChallenge1 = parse(challenge1);
final DigestScheme authscheme = new DigestScheme(); final DigestScheme authscheme = new DigestScheme();
@ -528,7 +528,7 @@ public class TestDigestScheme {
Assert.assertEquals(cnonce1, cnonce2); Assert.assertEquals(cnonce1, cnonce2);
Assert.assertEquals(sessionKey1, sessionKey2); Assert.assertEquals(sessionKey1, sessionKey2);
final String challenge2 = AuthSchemes.DIGEST.id + " qop=\"auth\", algorithm=MD5-sess, nonce=\"1234567890abcdef\", " + final String challenge2 = StandardAuthScheme.DIGEST + " qop=\"auth\", algorithm=MD5-sess, nonce=\"1234567890abcdef\", " +
"charset=utf-8, realm=\"subnet.domain.com\""; "charset=utf-8, realm=\"subnet.domain.com\"";
final AuthChallenge authChallenge2 = parse(challenge2); final AuthChallenge authChallenge2 = parse(challenge2);
authscheme.processChallenge(authChallenge2, null); authscheme.processChallenge(authChallenge2, null);
@ -543,7 +543,7 @@ public class TestDigestScheme {
Assert.assertEquals(cnonce1, cnonce3); Assert.assertEquals(cnonce1, cnonce3);
Assert.assertEquals(sessionKey1, sessionKey3); Assert.assertEquals(sessionKey1, sessionKey3);
final String challenge3 = AuthSchemes.DIGEST.id + " qop=\"auth\", algorithm=MD5-sess, nonce=\"fedcba0987654321\", " + final String challenge3 = StandardAuthScheme.DIGEST + " qop=\"auth\", algorithm=MD5-sess, nonce=\"fedcba0987654321\", " +
"charset=utf-8, realm=\"subnet.domain.com\""; "charset=utf-8, realm=\"subnet.domain.com\"";
final AuthChallenge authChallenge3 = parse(challenge3); final AuthChallenge authChallenge3 = parse(challenge3);
authscheme.processChallenge(authChallenge3, null); authscheme.processChallenge(authChallenge3, null);
@ -595,7 +595,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge = AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " + final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
"qop=\"auth,auth-int\""; "qop=\"auth,auth-int\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final DigestScheme authscheme = new DigestScheme(); final DigestScheme authscheme = new DigestScheme();
@ -622,7 +622,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge = AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " + final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
"qop=\"auth-int\""; "qop=\"auth-int\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final DigestScheme authscheme = new DigestScheme(); final DigestScheme authscheme = new DigestScheme();
@ -650,7 +650,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge = AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " + final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
"qop=\"auth,auth-int\""; "qop=\"auth,auth-int\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final DigestScheme authscheme = new DigestScheme(); final DigestScheme authscheme = new DigestScheme();
@ -677,7 +677,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge = AuthSchemes.DIGEST.id + " Realm=\"-\", " + final String challenge = StandardAuthScheme.DIGEST + " Realm=\"-\", " +
"nonce=\"YjYuNGYyYmJhMzUuY2I5ZDhlZDE5M2ZlZDM 1Mjk3NGJkNTIyYjgyNTcwMjQ=\", " + "nonce=\"YjYuNGYyYmJhMzUuY2I5ZDhlZDE5M2ZlZDM 1Mjk3NGJkNTIyYjgyNTcwMjQ=\", " +
"opaque=\"98700A3D9CE17065E2246B41035C6609\", qop=\"auth\""; "opaque=\"98700A3D9CE17065E2246B41035C6609\", qop=\"auth\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
@ -699,7 +699,7 @@ public class TestDigestScheme {
final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray()); final Credentials creds = new UsernamePasswordCredentials("username","password".toCharArray());
credentialsProvider.setCredentials(authScope, creds); credentialsProvider.setCredentials(authScope, creds);
final String challenge = AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " + final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
"qop=\"auth-int\""; "qop=\"auth-int\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final DigestScheme authscheme = new DigestScheme(); final DigestScheme authscheme = new DigestScheme();
@ -711,7 +711,7 @@ public class TestDigestScheme {
@Test @Test
public void testSerialization() throws Exception { public void testSerialization() throws Exception {
final String challenge = AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " + final String challenge = StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
"qop=\"auth,auth-int\""; "qop=\"auth,auth-int\"";
final AuthChallenge authChallenge = parse(challenge); final AuthChallenge authChallenge = parse(challenge);
final DigestScheme digestScheme = new DigestScheme(); final DigestScheme digestScheme = new DigestScheme();

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.Credentials;
import org.apache.hc.client5.http.auth.CredentialsProvider; import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy; import org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy;
import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.http.HttpHeaders;
@ -69,7 +69,7 @@ public class TestHttpAuthenticator {
@Override @Override
public String getName() { public String getName() {
return AuthSchemes.BASIC.id; return StandardAuthScheme.BASIC;
} }
} }
@ -94,9 +94,9 @@ public class TestHttpAuthenticator {
this.credentialsProvider = Mockito.mock(CredentialsProvider.class); this.credentialsProvider = Mockito.mock(CredentialsProvider.class);
this.context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider); this.context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider);
this.authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create() this.authSchemeRegistry = RegistryBuilder.<AuthSchemeFactory>create()
.register(AuthSchemes.BASIC.id, BasicSchemeFactory.INSTANCE) .register(StandardAuthScheme.BASIC, BasicSchemeFactory.INSTANCE)
.register(AuthSchemes.DIGEST.id, DigestSchemeFactory.INSTANCE) .register(StandardAuthScheme.DIGEST, DigestSchemeFactory.INSTANCE)
.register(AuthSchemes.NTLM.id, NTLMSchemeFactory.INSTANCE).build(); .register(StandardAuthScheme.NTLM, NTLMSchemeFactory.INSTANCE).build();
this.context.setAttribute(HttpClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry); this.context.setAttribute(HttpClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
this.authCache = Mockito.mock(AuthCache.class); this.authCache = Mockito.mock(AuthCache.class);
this.context.setAttribute(HttpClientContext.AUTH_CACHE, this.authCache); this.context.setAttribute(HttpClientContext.AUTH_CACHE, this.authCache);
@ -106,7 +106,7 @@ public class TestHttpAuthenticator {
@Test @Test
public void testUpdateAuthExchange() throws Exception { public void testUpdateAuthExchange() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED"); final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=test"); response.setHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=test");
Assert.assertTrue(this.httpAuthenticator.isChallenged( Assert.assertTrue(this.httpAuthenticator.isChallenged(
this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context)); this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context));
Mockito.verifyZeroInteractions(this.authCache); Mockito.verifyZeroInteractions(this.authCache);
@ -115,7 +115,7 @@ public class TestHttpAuthenticator {
@Test @Test
public void testAuthenticationRequestedAfterSuccess() throws Exception { public void testAuthenticationRequestedAfterSuccess() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED"); final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=test"); response.setHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=test");
this.authExchange.select(this.authScheme); this.authExchange.select(this.authScheme);
this.authExchange.setState(AuthExchange.State.SUCCESS); this.authExchange.setState(AuthExchange.State.SUCCESS);
@ -165,8 +165,8 @@ public class TestHttpAuthenticator {
public void testAuthentication() throws Exception { public void testAuthentication() throws Exception {
final HttpHost host = new HttpHost("somehost", 80); final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED"); final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=\"test\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"1234\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\""));
final Credentials credentials = new UsernamePasswordCredentials("user", "pass".toCharArray()); final Credentials credentials = new UsernamePasswordCredentials("user", "pass".toCharArray());
@ -183,10 +183,10 @@ public class TestHttpAuthenticator {
Assert.assertNotNull(options); Assert.assertNotNull(options);
final AuthScheme authScheme1 = options.poll(); final AuthScheme authScheme1 = options.poll();
Assert.assertNotNull(authScheme1); Assert.assertNotNull(authScheme1);
Assert.assertEquals(AuthSchemes.DIGEST.id, authScheme1.getName()); Assert.assertEquals(StandardAuthScheme.DIGEST, authScheme1.getName());
final AuthScheme authScheme2 = options.poll(); final AuthScheme authScheme2 = options.poll();
Assert.assertNotNull(authScheme2); Assert.assertNotNull(authScheme2);
Assert.assertEquals(AuthSchemes.BASIC.id, authScheme2.getName()); Assert.assertEquals(StandardAuthScheme.BASIC, authScheme2.getName());
Assert.assertNull(options.poll()); Assert.assertNull(options.poll());
} }
@ -195,11 +195,11 @@ public class TestHttpAuthenticator {
final HttpHost host = new HttpHost("somehost", 80); final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = final HttpResponse response =
new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED"); new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=\"test\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"1234\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"1234\""));
final Credentials credentials = new UsernamePasswordCredentials("user", "pass".toCharArray()); final Credentials credentials = new UsernamePasswordCredentials("user", "pass".toCharArray());
Mockito.when(this.credentialsProvider.getCredentials(Mockito.eq(new AuthScope(host, "test", AuthSchemes.BASIC.id)), Mockito.when(this.credentialsProvider.getCredentials(Mockito.eq(new AuthScope(host, "test", StandardAuthScheme.BASIC)),
Mockito.<HttpContext>any())).thenReturn(credentials); Mockito.<HttpContext>any())).thenReturn(credentials);
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy(); final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
@ -212,7 +212,7 @@ public class TestHttpAuthenticator {
Assert.assertNotNull(options); Assert.assertNotNull(options);
final AuthScheme authScheme1 = options.poll(); final AuthScheme authScheme1 = options.poll();
Assert.assertNotNull(authScheme1); Assert.assertNotNull(authScheme1);
Assert.assertEquals(AuthSchemes.BASIC.id, authScheme1.getName()); Assert.assertEquals(StandardAuthScheme.BASIC, authScheme1.getName());
Assert.assertNull(options.poll()); Assert.assertNull(options.poll());
} }
@ -244,8 +244,8 @@ public class TestHttpAuthenticator {
public void testAuthenticationNoCredentials() throws Exception { public void testAuthenticationNoCredentials() throws Exception {
final HttpHost host = new HttpHost("somehost", 80); final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED"); final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=\"test\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"1234\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"1234\""));
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy(); final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
@ -257,8 +257,8 @@ public class TestHttpAuthenticator {
public void testAuthenticationFailed() throws Exception { public void testAuthenticationFailed() throws Exception {
final HttpHost host = new HttpHost("somehost", 80); final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED"); final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=\"test\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"1234\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"1234\""));
this.authExchange.setState(AuthExchange.State.CHALLENGED); this.authExchange.setState(AuthExchange.State.CHALLENGED);
this.authExchange.select(this.authScheme); this.authExchange.select(this.authScheme);
@ -277,8 +277,8 @@ public class TestHttpAuthenticator {
public void testAuthenticationFailedPreviously() throws Exception { public void testAuthenticationFailedPreviously() throws Exception {
final HttpHost host = new HttpHost("somehost", 80); final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED"); final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=\"test\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"1234\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"1234\""));
this.authExchange.setState(AuthExchange.State.FAILURE); this.authExchange.setState(AuthExchange.State.FAILURE);
@ -294,8 +294,8 @@ public class TestHttpAuthenticator {
public void testAuthenticationFailure() throws Exception { public void testAuthenticationFailure() throws Exception {
final HttpHost host = new HttpHost("somehost", 80); final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED"); final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=\"test\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"1234\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\""));
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy(); final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
@ -312,8 +312,8 @@ public class TestHttpAuthenticator {
public void testAuthenticationHandshaking() throws Exception { public void testAuthenticationHandshaking() throws Exception {
final HttpHost host = new HttpHost("somehost", 80); final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED"); final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=\"test\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=\"test\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.DIGEST.id + " realm=\"realm1\", stale=true, nonce=\"1234\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.DIGEST + " realm=\"realm1\", stale=true, nonce=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\""));
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy(); final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
@ -331,11 +331,11 @@ public class TestHttpAuthenticator {
public void testAuthenticationNoMatchingChallenge() throws Exception { public void testAuthenticationNoMatchingChallenge() throws Exception {
final HttpHost host = new HttpHost("somehost", 80); final HttpHost host = new HttpHost("somehost", 80);
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED"); final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.DIGEST.id + " realm=\"realm1\", nonce=\"1234\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.DIGEST + " realm=\"realm1\", nonce=\"1234\""));
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\"")); response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\""));
final Credentials credentials = new UsernamePasswordCredentials("user", "pass".toCharArray()); final Credentials credentials = new UsernamePasswordCredentials("user", "pass".toCharArray());
Mockito.when(this.credentialsProvider.getCredentials(Mockito.eq(new AuthScope(host, "realm1", AuthSchemes.DIGEST.id)), Mockito.when(this.credentialsProvider.getCredentials(Mockito.eq(new AuthScope(host, "realm1", StandardAuthScheme.DIGEST)),
Mockito.<HttpContext>any())).thenReturn(credentials); Mockito.<HttpContext>any())).thenReturn(credentials);
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy(); final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
@ -351,7 +351,7 @@ public class TestHttpAuthenticator {
Assert.assertNotNull(options); Assert.assertNotNull(options);
final AuthScheme authScheme1 = options.poll(); final AuthScheme authScheme1 = options.poll();
Assert.assertNotNull(authScheme1); Assert.assertNotNull(authScheme1);
Assert.assertEquals(AuthSchemes.DIGEST.id, authScheme1.getName()); Assert.assertEquals(StandardAuthScheme.DIGEST, authScheme1.getName());
Assert.assertNull(options.poll()); Assert.assertNull(options.poll());
} }

View File

@ -28,11 +28,12 @@ package org.apache.hc.client5.http.impl.auth;
import java.net.Authenticator; import java.net.Authenticator;
import java.net.Authenticator.RequestorType; import java.net.Authenticator.RequestorType;
import java.util.Locale;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.PasswordAuthentication; import java.net.PasswordAuthentication;
import java.net.URL; import java.net.URL;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.Credentials; import org.apache.hc.client5.http.auth.Credentials;
import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.classic.methods.HttpGet;
@ -92,7 +93,7 @@ public class TestSystemDefaultCredentialsProvider {
final AuthenticatorDelegate authenticatorDelegate = installAuthenticator(AUTH1); final AuthenticatorDelegate authenticatorDelegate = installAuthenticator(AUTH1);
final URL httpRequestUrl = new URL(TARGET_SCHEME1, TARGET_HOST1, TARGET_PORT1, "/"); final URL httpRequestUrl = new URL(TARGET_SCHEME1, TARGET_HOST1, TARGET_PORT1, "/");
final AuthScope authScope = new AuthScope(PROXY_PROTOCOL1, PROXY_HOST1, PROXY_PORT1, PROMPT1, AuthSchemes.BASIC.id); final AuthScope authScope = new AuthScope(PROXY_PROTOCOL1, PROXY_HOST1, PROXY_PORT1, PROMPT1, StandardAuthScheme.BASIC);
final HttpCoreContext coreContext = new HttpCoreContext(); final HttpCoreContext coreContext = new HttpCoreContext();
coreContext.setAttribute(HttpCoreContext.HTTP_REQUEST, new HttpGet(httpRequestUrl.toURI())); coreContext.setAttribute(HttpCoreContext.HTTP_REQUEST, new HttpGet(httpRequestUrl.toURI()));
@ -100,7 +101,7 @@ public class TestSystemDefaultCredentialsProvider {
new SystemDefaultCredentialsProvider().getCredentials(authScope, coreContext); new SystemDefaultCredentialsProvider().getCredentials(authScope, coreContext);
Mockito.verify(authenticatorDelegate).getPasswordAuthentication(PROXY_HOST1, null, PROXY_PORT1, PROXY_PROTOCOL1, Mockito.verify(authenticatorDelegate).getPasswordAuthentication(PROXY_HOST1, null, PROXY_PORT1, PROXY_PROTOCOL1,
PROMPT1, AuthSchemes.BASIC.id, httpRequestUrl, PROMPT1, StandardAuthScheme.BASIC.toUpperCase(Locale.ROOT), httpRequestUrl,
RequestorType.SERVER); RequestorType.SERVER);
Assert.assertNotNull(receivedCredentials); Assert.assertNotNull(receivedCredentials);
Assert.assertEquals(AUTH1.getUserName(), receivedCredentials.getUserPrincipal().getName()); Assert.assertEquals(AUTH1.getUserName(), receivedCredentials.getUserPrincipal().getName());
@ -112,13 +113,13 @@ public class TestSystemDefaultCredentialsProvider {
final AuthenticatorDelegate authenticatorDelegate = installAuthenticator(AUTH1); final AuthenticatorDelegate authenticatorDelegate = installAuthenticator(AUTH1);
final AuthScope authScope = new AuthScope(PROXY_PROTOCOL1, PROXY_HOST1, PROXY_PORT1, PROMPT1, AuthSchemes.BASIC.id); final AuthScope authScope = new AuthScope(PROXY_PROTOCOL1, PROXY_HOST1, PROXY_PORT1, PROMPT1, StandardAuthScheme.BASIC);
final Credentials receivedCredentials = final Credentials receivedCredentials =
new SystemDefaultCredentialsProvider().getCredentials(authScope, null); new SystemDefaultCredentialsProvider().getCredentials(authScope, null);
Mockito.verify(authenticatorDelegate).getPasswordAuthentication(PROXY_HOST1, null, PROXY_PORT1, PROXY_PROTOCOL1, Mockito.verify(authenticatorDelegate).getPasswordAuthentication(PROXY_HOST1, null, PROXY_PORT1, PROXY_PROTOCOL1,
PROMPT1, AuthSchemes.BASIC.id, null, PROMPT1, StandardAuthScheme.BASIC.toUpperCase(Locale.ROOT), null,
RequestorType.SERVER); RequestorType.SERVER);
Assert.assertNotNull(receivedCredentials); Assert.assertNotNull(receivedCredentials);
Assert.assertEquals(AUTH1.getUserName(), receivedCredentials.getUserPrincipal().getName()); Assert.assertEquals(AUTH1.getUserName(), receivedCredentials.getUserPrincipal().getName());

View File

@ -36,7 +36,7 @@ import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.RouteInfo; import org.apache.hc.client5.http.RouteInfo;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthScheme; import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.ChallengeType; import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
@ -245,7 +245,7 @@ public class TestConnectExec {
final HttpClientContext context = new HttpClientContext(); final HttpClientContext context = new HttpClientContext();
final ClassicHttpRequest request = new HttpGet("http://bar/test"); final ClassicHttpRequest request = new HttpGet("http://bar/test");
final ClassicHttpResponse response1 = new BasicClassicHttpResponse(407, "Huh?"); final ClassicHttpResponse response1 = new BasicClassicHttpResponse(407, "Huh?");
response1.setHeader(HttpHeaders.PROXY_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=test"); response1.setHeader(HttpHeaders.PROXY_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=test");
final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
response1.setEntity(EntityBuilder.create() response1.setEntity(EntityBuilder.create()
.setStream(inStream1) .setStream(inStream1)
@ -286,7 +286,7 @@ public class TestConnectExec {
final HttpClientContext context = new HttpClientContext(); final HttpClientContext context = new HttpClientContext();
final ClassicHttpRequest request = new HttpGet("http://bar/test"); final ClassicHttpRequest request = new HttpGet("http://bar/test");
final ClassicHttpResponse response1 = new BasicClassicHttpResponse(407, "Huh?"); final ClassicHttpResponse response1 = new BasicClassicHttpResponse(407, "Huh?");
response1.setHeader(HttpHeaders.PROXY_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=test"); response1.setHeader(HttpHeaders.PROXY_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=test");
final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
response1.setEntity(EntityBuilder.create() response1.setEntity(EntityBuilder.create()
.setStream(inStream1) .setStream(inStream1)

View File

@ -39,7 +39,7 @@ import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.auth.AuthChallenge; import org.apache.hc.client5.http.auth.AuthChallenge;
import org.apache.hc.client5.http.auth.AuthExchange; import org.apache.hc.client5.http.auth.AuthExchange;
import org.apache.hc.client5.http.auth.AuthScheme; import org.apache.hc.client5.http.auth.AuthScheme;
import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.AuthScope; import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.ChallengeType; import org.apache.hc.client5.http.auth.ChallengeType;
import org.apache.hc.client5.http.auth.Credentials; import org.apache.hc.client5.http.auth.Credentials;
@ -214,7 +214,7 @@ public class TestProtocolExec {
final HttpClientContext context = new HttpClientContext(); final HttpClientContext context = new HttpClientContext();
final ClassicHttpRequest request = new HttpGet("http://foo/test"); final ClassicHttpRequest request = new HttpGet("http://foo/test");
final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?"); final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?");
response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=test"); response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=test");
final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
response1.setEntity(EntityBuilder.create() response1.setEntity(EntityBuilder.create()
.setStream(inStream1) .setStream(inStream1)
@ -253,7 +253,7 @@ public class TestProtocolExec {
final HttpRoute route = new HttpRoute(target, proxy); final HttpRoute route = new HttpRoute(target, proxy);
final ClassicHttpRequest request = new HttpGet("http://foo/test"); final ClassicHttpRequest request = new HttpGet("http://foo/test");
final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?"); final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?");
response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=test"); response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=test");
final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
response1.setEntity(EntityBuilder.create() response1.setEntity(EntityBuilder.create()
.setStream(inStream1) .setStream(inStream1)
@ -305,7 +305,7 @@ public class TestProtocolExec {
.setStream(inStream0) .setStream(inStream0)
.build()); .build());
final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?"); final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?");
response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, AuthSchemes.BASIC.id + " realm=test"); response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.BASIC + " realm=test");
final InputStream inStream1 = new ByteArrayInputStream(new byte[] {1, 2, 3}); final InputStream inStream1 = new ByteArrayInputStream(new byte[] {1, 2, 3});
response1.setEntity(EntityBuilder.create() response1.setEntity(EntityBuilder.create()
.setStream(inStream1) .setStream(inStream1)