Class AuthenticationHandler
java.lang.Object
org.apache.hc.client5.http.impl.auth.AuthenticationHandler
- Direct Known Subclasses:
HttpAuthenticator
Internal utility class that implements commons aspects of the client side
HTTP authentication.
- Since:
- 5.4
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Loggerprivate final AuthChallengeParser -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAuthResponse(org.apache.hc.core5.http.HttpHost host, ChallengeType challengeType, org.apache.hc.core5.http.HttpRequest request, AuthExchange authExchange, org.apache.hc.core5.http.protocol.HttpContext context) Generates a response to the authentication challenge based on the actualAuthExchangestate and adds it to the givenHttpRequestmessage .private booleancheckChallenged(ChallengeType challengeType, org.apache.hc.core5.http.HttpResponse response, HttpClientContext clientContext) Determines whether the given response represents an authentication challenge of challangeType, without changing theAuthExchangestate.extractChallengeMap(ChallengeType challengeType, org.apache.hc.core5.http.HttpResponse response, HttpClientContext context) booleanhandleResponse(org.apache.hc.core5.http.HttpHost host, ChallengeType challengeType, org.apache.hc.core5.http.HttpResponse response, AuthenticationStrategy authStrategy, AuthExchange authExchange, org.apache.hc.core5.http.protocol.HttpContext context) Handles the response from the opposite endpoint and updates theAuthExchangestate based on the challenge presented in the response message using the givenAuthenticationStrategy.booleanisChallenged(org.apache.hc.core5.http.HttpHost host, ChallengeType challengeType, org.apache.hc.core5.http.HttpResponse response, AuthExchange authExchange, org.apache.hc.core5.http.protocol.HttpContext context) Determines whether the given response represents an authentication challenge, and updates theAuthExchangestate.booleanisChallengeExpected(AuthExchange authExchange) Determines if the scheme requires an auth challenge for responses that do not have a challenge HTTP code.
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
parser
-
-
Constructor Details
-
AuthenticationHandler
public AuthenticationHandler()
-
-
Method Details
-
isChallenged
public boolean isChallenged(org.apache.hc.core5.http.HttpHost host, ChallengeType challengeType, org.apache.hc.core5.http.HttpResponse response, AuthExchange authExchange, org.apache.hc.core5.http.protocol.HttpContext context) Determines whether the given response represents an authentication challenge, and updates theAuthExchangestate.- Parameters:
host- the hostname of the opposite endpoint.challengeType- the challenge type (target or proxy).response- the response message head.authExchange- the current authentication exchange state. Gets updated.context- the current execution context.- Returns:
trueif the response message represents an authentication challenge,falseotherwise.
-
checkChallenged
private boolean checkChallenged(ChallengeType challengeType, org.apache.hc.core5.http.HttpResponse response, HttpClientContext clientContext) Determines whether the given response represents an authentication challenge of challangeType, without changing theAuthExchangestate.- Parameters:
challengeType- the challenge type (target or proxy).response- the response message head.clientContext- the current execution context.- Returns:
trueif the response message represents an authentication challenge,falseotherwise.
-
isChallengeExpected
Determines if the scheme requires an auth challenge for responses that do not have a challenge HTTP code. (i.e whether it needs a mutual authentication token) -
extractChallengeMap
public Map<String, AuthChallenge> extractChallengeMap(ChallengeType challengeType, org.apache.hc.core5.http.HttpResponse response, HttpClientContext context) -
handleResponse
public boolean handleResponse(org.apache.hc.core5.http.HttpHost host, ChallengeType challengeType, org.apache.hc.core5.http.HttpResponse response, AuthenticationStrategy authStrategy, AuthExchange authExchange, org.apache.hc.core5.http.protocol.HttpContext context) throws AuthenticationException, MalformedChallengeException Handles the response from the opposite endpoint and updates theAuthExchangestate based on the challenge presented in the response message using the givenAuthenticationStrategy.- Parameters:
host- the hostname of the opposite endpoint.challengeType- the challenge type (target or proxy).response- the response message head.authStrategy- the authentication strategy.authExchange- the current authentication exchange state.context- the current execution context.- Returns:
trueif the request needs-to be re-sent,falseif the authentication is complete (successful or not).- Throws:
AuthenticationException- if the AuthScheme throws one. In most cases this indicates a client side problem, as final server error responses are simply returned.MalformedChallengeException- if the AuthScheme throws one. In most cases this indicates a client side problem, as final server error responses are simply returned.
-
addAuthResponse
public void addAuthResponse(org.apache.hc.core5.http.HttpHost host, ChallengeType challengeType, org.apache.hc.core5.http.HttpRequest request, AuthExchange authExchange, org.apache.hc.core5.http.protocol.HttpContext context) Generates a response to the authentication challenge based on the actualAuthExchangestate and adds it to the givenHttpRequestmessage .- Parameters:
host- the hostname of the opposite endpoint.challengeType- the challenge type (target or proxy).request- the request message head.authExchange- the current authentication exchange state.context- the current execution context.
-