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 {