From 33bceb3cc8f007ab8ddddba45b172a4f431ce0cb Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 1 Feb 2019 12:21:21 +0100 Subject: [PATCH] Fixes #3234 - AuthenticationProtocolHandler should not cache the failed results. Now only caching authentication results for 2xx and 3xx codes. Signed-off-by: Simone Bordet --- .../eclipse/jetty/client/AuthenticationProtocolHandler.java | 5 ++++- .../eclipse/jetty/client/HttpClientAuthenticationTest.java | 3 +++ 2 files changed, 7 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 1fe2cd264cf..1388931e233 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 @@ -37,6 +37,7 @@ import org.eclipse.jetty.client.api.Result; import org.eclipse.jetty.client.util.BufferingResponseListener; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpHeader; +import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.QuotedCSV; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -309,7 +310,9 @@ public abstract class AuthenticationProtocolHandler implements ProtocolHandler @Override public void onSuccess(Response response) { - client.getAuthenticationStore().addAuthenticationResult(authenticationResult); + int status = response.getStatus(); + if (HttpStatus.isSuccess(status) || HttpStatus.isRedirection(status)) + client.getAuthenticationStore().addAuthenticationResult(authenticationResult); } } } 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 9a2b22c2a55..5e3307746a2 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 @@ -369,6 +369,9 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest ContentResponse response = request.timeout(5, TimeUnit.SECONDS).send(); assertNotNull(response); assertEquals(401, response.getStatus()); + + Authentication.Result authenticationResult = authenticationStore.findAuthenticationResult(uri); + assertNull(authenticationResult); } @ParameterizedTest