Interface TokenAPIHandler
-
- All Superinterfaces:
java.lang.AutoCloseable
- All Known Implementing Classes:
AbstractRemoteAuthTokenAPIHandler,AbstractTokenAPIHandler,CodeFlowAuthTokenAPIHandler,EnvironmentTokenAPIHandler,FixedTokenAPIHandler,PasswordAuthTokenAPIHandler
public interface TokenAPIHandler extends java.lang.AutoCloseable
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddToHeaders(HttpHeaderMap headers)Override this to add authentication tokens.java.net.URIbuildWebSocketURI(java.lang.String path)Build a complete uri from the webSocketApi and path.booleancheckResponse(java.net.http.HttpResponse<java.io.InputStream> httpResponse, int retryCount)The default way to check responses for errors and extract error messages.voidclose()Close the underlying httpClientHandler.DecodedTokendecodeToken()Decode the payload part of the internal token.static DecodedTokendecodeToken(java.lang.String token)Decode the payload part of any token.java.time.InstantexpiryInstant()Calculate the Instant after which the token should be refreshed.java.net.URIgetApiURIOf(java.lang.String apiName)Determine the API URI path for a named API.AbstractAPIHandler.Conf<?>getConf()Return a copy of the configuration.java.net.http.HttpClientgetOrBuildClient()java.net.URIgetRootApiURI()java.lang.StringgetToken()Return the current token.java.lang.StringgetUserAgent()VersionResponsegetVersionMap()Returns the current versionMap.booleanhasRefreshToken()Check for existence of a refresh token in the TokenAPIHandler.booleanhasToken()Check for existence of a token in the TokenAPIHandler.voidrefreshToken()Refresh an invalid token.voidrevokeToken()Revoke a token
-
-
-
Method Detail
-
getConf
AbstractAPIHandler.Conf<?> getConf()
Return a copy of the configuration.- Returns:
- A copy of the configuration.
- See Also:
AuthenticatedAPIHandler- Implementation Note:
- Please take note, that the included httpClientHandler of this class will be
added to the returned
AbstractAPIHandler.Confand therefore will be shared among all APIHandlers that use this configuration.
-
addToHeaders
void addToHeaders(HttpHeaderMap headers)
Override this to add authentication tokens. TokenHandlers do not have tokens, so this only returns default headers.- Parameters:
headers- Map of headers with initial values.
-
getToken
java.lang.String getToken() throws java.io.IOException, java.lang.InterruptedException, HiroExceptionReturn the current token.- Returns:
- The current token.
- Throws:
java.lang.InterruptedException- When call gets interrupted.java.io.IOException- When call has IO errors.HiroException- On Hiro protocol / handling errors.
-
decodeToken
DecodedToken decodeToken() throws HiroException, java.io.IOException, java.lang.InterruptedException
Decode the payload part of the internal token.- Returns:
- Decoded token as
DecodedToken. - Throws:
java.lang.InterruptedException- When call gets interrupted.java.io.IOException- When call has IO errors.HiroException- On Hiro protocol / handling errors.
-
refreshToken
void refreshToken() throws java.io.IOException, java.lang.InterruptedException, HiroExceptionRefresh an invalid token.- Throws:
java.lang.InterruptedException- When call gets interrupted.java.io.IOException- When call has IO errors.HiroException- On Hiro protocol / handling errors.
-
revokeToken
void revokeToken() throws java.io.IOException, java.lang.InterruptedException, HiroExceptionRevoke a token- Throws:
java.lang.InterruptedException- When call gets interrupted.java.io.IOException- When call has IO errors.HiroException- On Hiro protocol / handling errors.
-
hasToken
boolean hasToken()
Check for existence of a token in the TokenAPIHandler.- Returns:
- true if a token has been set or retrieved, false if the token is empty.
-
hasRefreshToken
boolean hasRefreshToken()
Check for existence of a refresh token in the TokenAPIHandler.- Returns:
- true if a refresh token retrieved, false if no such token exists or these tokens are not applicable for this TokenAPIHandler.
-
expiryInstant
java.time.Instant expiryInstant()
Calculate the Instant after which the token should be refreshed.- Returns:
- The Instant after which the token shall be refreshed. null if token cannot be refreshed.
-
checkResponse
boolean checkResponse(java.net.http.HttpResponse<java.io.InputStream> httpResponse, int retryCount) throws HiroException, java.io.IOException, java.lang.InterruptedExceptionThe default way to check responses for errors and extract error messages.- Parameters:
httpResponse- The httpResponse from the HttpRequestretryCount- current counter for retries- Returns:
- true for a retry, false otherwise.
- Throws:
TokenUnauthorizedException- When the statusCode is 401.HiroHttpException- When the statusCode is < 200 or > 399.HiroException- On internal errors regarding hiro data processing.java.io.IOException- On IO errors.java.lang.InterruptedException- When a call (possibly of an overwritten method) gets interrupted.
-
getApiURIOf
java.net.URI getApiURIOf(java.lang.String apiName) throws java.io.IOException, java.lang.InterruptedException, HiroExceptionDetermine the API URI path for a named API.- Parameters:
apiName- Name of the API- Returns:
- The URI for that API
- Throws:
HiroException- When the request fails.java.io.IOException- When the connection fails.java.lang.InterruptedException- When interrupted.
-
buildWebSocketURI
java.net.URI buildWebSocketURI(java.lang.String path)
Build a complete uri from the webSocketApi and path.- Parameters:
path- The path to append to webSocketURI.- Returns:
- The constructed URI
-
getOrBuildClient
java.net.http.HttpClient getOrBuildClient()
- Returns:
- The HttpClient to use with this class.
-
getVersionMap
VersionResponse getVersionMap() throws HiroException, java.io.IOException, java.lang.InterruptedException
Returns the current versionMap. If no versionMap is available, it will be requested, cached and then returned. if a sharedConnectionHandler is set, the versionMap will be obtained from there.- Returns:
- The (cached) versionMap.
- Throws:
HiroException- When the request fails.java.io.IOException- When the connection fails.java.lang.InterruptedException- When interrupted.
-
getRootApiURI
java.net.URI getRootApiURI()
- Returns:
- Root URI of the API.
-
getUserAgent
java.lang.String getUserAgent()
-
close
void close()
Close the underlying httpClientHandler.- Specified by:
closein interfacejava.lang.AutoCloseable
-
decodeToken
static DecodedToken decodeToken(java.lang.String token) throws HiroException, java.io.IOException
Decode the payload part of any token.- Parameters:
token- The token to decode.- Returns:
- Decoded token as
DecodedToken. - Throws:
java.io.IOException- When call has IO errors.HiroException- On Hiro protocol / handling errors.
-
-