Fixes #3234 - AuthenticationProtocolHandler should not cache the failed results.

Now only caching authentication results for 2xx and 3xx codes.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2019-02-01 12:21:21 +01:00
parent 66873e8637
commit 33bceb3cc8
2 changed files with 7 additions and 1 deletions

View File

@ -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);
}
}
}

View File

@ -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