From 29dccf668c614d38b1d01ff2be8b4d614f66e9f1 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 12 Apr 2018 10:33:47 +1000 Subject: [PATCH] Changes after review 1 Regex will now look for comma and spaces before realm. Preventing issues accepting params with realm as a suffix like blahrealm. Stops adding double commas when extracting realm param. Signed-off-by: Lachlan Roberts --- .../jetty/client/AuthenticationProtocolHandler.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 159b252ee3e..6d3a245dce6 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 @@ -42,7 +42,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(.*,\\s*)?realm=\"([^\"]*)\"\\s*,?\\s*(.*)", Pattern.CASE_INSENSITIVE); private final HttpClient client; private final int maxContentLength; @@ -242,7 +242,12 @@ public abstract class AuthenticationProtocolHandler implements ProtocolHandler { String type = matcher.group(1); String realm = matcher.group(3); - String params = matcher.group(2) + matcher.group(4); + String params; + if(matcher.group(2) != null) + params = matcher.group(2) + matcher.group(4); + else + params = matcher.group(4); + Authentication.HeaderInfo headerInfo = new Authentication.HeaderInfo(type, realm, params, getAuthorizationHeader()); result.add(headerInfo); }