Package com.google.auth.http
Class HttpCredentialsAdapter
- java.lang.Object
-
- com.google.auth.http.HttpCredentialsAdapter
-
- All Implemented Interfaces:
com.google.api.client.http.HttpRequestInitializer
,com.google.api.client.http.HttpUnsuccessfulResponseHandler
public class HttpCredentialsAdapter extends java.lang.Object implements com.google.api.client.http.HttpRequestInitializer, com.google.api.client.http.HttpUnsuccessfulResponseHandler
A wrapper for using Credentials with the Google API Client Libraries for Java with Http.
-
-
Field Summary
Fields Modifier and Type Field Description private Credentials
credentials
private static java.util.regex.Pattern
INVALID_TOKEN_ERROR
In case an abnormal HTTP response is received withWWW-Authenticate
header, and its value contains this error pattern, we will try to refresh the token.private static java.util.logging.Logger
LOGGER
-
Constructor Summary
Constructors Constructor Description HttpCredentialsAdapter(Credentials credentials)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Credentials
getCredentials()
A getter for the credentials instance being usedboolean
handleResponse(com.google.api.client.http.HttpRequest request, com.google.api.client.http.HttpResponse response, boolean supportsRetry)
void
initialize(com.google.api.client.http.HttpRequest request)
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
INVALID_TOKEN_ERROR
private static final java.util.regex.Pattern INVALID_TOKEN_ERROR
In case an abnormal HTTP response is received withWWW-Authenticate
header, and its value contains this error pattern, we will try to refresh the token.
-
credentials
private final Credentials credentials
-
-
Constructor Detail
-
HttpCredentialsAdapter
public HttpCredentialsAdapter(Credentials credentials)
- Parameters:
credentials
- Credentials instance to adapt for HTTP
-
-
Method Detail
-
getCredentials
public Credentials getCredentials()
A getter for the credentials instance being used
-
initialize
public void initialize(com.google.api.client.http.HttpRequest request) throws java.io.IOException
Initialize the HTTP request prior to execution.
- Specified by:
initialize
in interfacecom.google.api.client.http.HttpRequestInitializer
- Parameters:
request
- HTTP request- Throws:
java.io.IOException
-
handleResponse
public boolean handleResponse(com.google.api.client.http.HttpRequest request, com.google.api.client.http.HttpResponse response, boolean supportsRetry)
Checks if
WWW-Authenticate
exists and contains a "Bearer" value (see rfc6750 section 3.1 for more details). If so, it refreshes the token in case the error code containsinvalid_token
. If there is no "Bearer" inWWW-Authenticate
and the status code isHttpStatusCodes.STATUS_CODE_UNAUTHORIZED
it refreshes the token. If the token refresh throws an I/O exception, this implementation will log the exception and returnfalse
.- Specified by:
handleResponse
in interfacecom.google.api.client.http.HttpUnsuccessfulResponseHandler
-
-