From 4aa512e4682ad6521459bd9f23ac697df7d2b70d Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 1 Apr 2016 14:29:11 +0200 Subject: [PATCH] Issue #184 - Empty Realm for BasicAuthentication. Fixed by allowing empty realms. --- .../jetty/client/AuthenticationProtocolHandler.java | 2 +- .../jetty/client/HttpClientAuthenticationTest.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/AuthenticationProtocolHandler.java b/jetty-client/src/main/java/org/eclipse/jetty/client/AuthenticationProtocolHandler.java index 6709f951200..4e67e1fbee0 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/AuthenticationProtocolHandler.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/AuthenticationProtocolHandler.java @@ -41,7 +41,7 @@ public abstract class AuthenticationProtocolHandler implements ProtocolHandler { public static final int DEFAULT_MAX_CONTENT_LENGTH = 16*1024; public static final Logger LOG = Log.getLogger(AuthenticationProtocolHandler.class); - private static final Pattern AUTHENTICATE_PATTERN = Pattern.compile("([^\\s]+)\\s+realm=\"([^\"]+)\"(.*)", Pattern.CASE_INSENSITIVE); + private static final Pattern AUTHENTICATE_PATTERN = Pattern.compile("([^\\s]+)\\s+realm=\"([^\"]*)\"(.*)", Pattern.CASE_INSENSITIVE); private final HttpClient client; private final int maxContentLength; 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 07cc0cde850..b68e7641c59 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 @@ -110,6 +110,15 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest test_Authentication(new BasicAuthentication(uri, realm, "basic", "basic")); } + @Test + public void test_BasicEmptyRealm() throws Exception + { + realm = ""; + startBasic(new EmptyServerHandler()); + URI uri = URI.create(scheme + "://localhost:" + connector.getLocalPort()); + test_Authentication(new BasicAuthentication(uri, realm, "basic", "basic")); + } + @Test public void test_DigestAuthentication() throws Exception {