From bef4b56fc04ab4191c5b3634afadf875a0600caf Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 17 Aug 2016 22:10:59 +0200 Subject: [PATCH] Fixes #806 - Jetty HttpClient authentication - missing any realm option. Introduced Authentication.ANY_REALM constant to use when specifying the realm in concrete subclasses, so that the realm match is skipped. --- .../java/org/eclipse/jetty/client/api/Authentication.java | 6 ++++++ .../eclipse/jetty/client/util/AbstractAuthentication.java | 2 +- .../jetty/client/HttpClientAuthenticationTest.java | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/api/Authentication.java b/jetty-client/src/main/java/org/eclipse/jetty/client/api/Authentication.java index 082e1c14288..750c88f4cc3 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/api/Authentication.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/api/Authentication.java @@ -38,6 +38,12 @@ import org.eclipse.jetty.util.Attributes; */ public interface Authentication { + /** + * Constant used to indicate that any realm will match. + * @see #matches(String, URI, String) + */ + public static final String ANY_REALM = "<>"; + /** * Matches {@link Authentication}s based on the given parameters * @param type the {@link Authentication} type such as "Basic" or "Digest" diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/util/AbstractAuthentication.java b/jetty-client/src/main/java/org/eclipse/jetty/client/util/AbstractAuthentication.java index 534ed44fdfb..c98758961ba 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/util/AbstractAuthentication.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/util/AbstractAuthentication.java @@ -52,7 +52,7 @@ public abstract class AbstractAuthentication implements Authentication if (!getType().equalsIgnoreCase(type)) return false; - if (!this.realm.equals(realm)) + if (!this.realm.equals(ANY_REALM) && !this.realm.equals(realm)) return false; return matchesURI(this.uri, uri); diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java index 6e686fcc87e..a44a035f2bb 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java @@ -119,6 +119,14 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest test_Authentication(new BasicAuthentication(uri, realm, "basic", "basic")); } + @Test + public void test_BasicAnyRealm() throws Exception + { + startBasic(new EmptyServerHandler()); + URI uri = URI.create(scheme + "://localhost:" + connector.getLocalPort()); + test_Authentication(new BasicAuthentication(uri, Authentication.ANY_REALM, "basic", "basic")); + } + @Test public void test_DigestAuthentication() throws Exception {