Class AbstractRemoteAuthTokenAPIHandler
- java.lang.Object
-
- co.arago.hiro.client.connection.AbstractAPIHandler
-
- co.arago.hiro.client.connection.AbstractVersionAPIHandler
-
- co.arago.hiro.client.connection.token.AbstractTokenAPIHandler
-
- co.arago.hiro.client.connection.token.AbstractRemoteAuthTokenAPIHandler
-
- All Implemented Interfaces:
TokenAPIHandler,java.lang.AutoCloseable
- Direct Known Subclasses:
CodeFlowAuthTokenAPIHandler,PasswordAuthTokenAPIHandler
public abstract class AbstractRemoteAuthTokenAPIHandler extends AbstractTokenAPIHandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractRemoteAuthTokenAPIHandler.Conf<T extends AbstractRemoteAuthTokenAPIHandler.Conf<T>>protected static classAbstractRemoteAuthTokenAPIHandler.TokenInfoExtends the TokenResponse with additional data and operations.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringapiNameprotected java.lang.StringapiPathprotected java.net.URIapiURIprotected java.lang.StringclientIdprotected java.lang.StringclientSecretprotected java.lang.Stringorganizationprotected java.lang.StringorganizationIdprotected AbstractRemoteAuthTokenAPIHandler.TokenInfotokenInfo-
Fields inherited from class co.arago.hiro.client.connection.AbstractAPIHandler
httpClientHandler, httpRequestTimeout, maxRetries, rootApiURI, title, userAgent, version, webSocketURI
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractRemoteAuthTokenAPIHandler(AbstractRemoteAuthTokenAPIHandler.Conf<?> builder)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancheckResponse(java.net.http.HttpResponse<java.io.InputStream> httpResponse, int retryCount)Check for the kind of error.java.time.InstantexpiryInstant()Calculate the Instant after which the token should be refreshed (expiresAt minus theAbstractRemoteAuthTokenAPIHandler.TokenInfo.refreshOffset).longgetRefreshOffset()java.lang.StringgetRefreshToken()java.lang.StringgetToken()Return the current token.java.net.URIgetURI(java.lang.String path)Construct my URI.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.voidrefreshToken(java.lang.String organization, java.lang.String organizationId)Refresh an invalid token.protected abstract voidrequestToken(java.lang.String organization, java.lang.String organizationId)Obtain a new token from the auth API.voidrevokeToken()Revoke a token.voidrevokeToken(java.lang.String tokenHint)Revoke a token.voidsetRefreshOffset(long refreshOffset)booleantokenExpired()Check for token expiration-
Methods inherited from class co.arago.hiro.client.connection.token.AbstractTokenAPIHandler
addToHeaders, close, decodeToken
-
Methods inherited from class co.arago.hiro.client.connection.AbstractVersionAPIHandler
getApiURIOf, getVersionMap, requestVersionMap
-
Methods inherited from class co.arago.hiro.client.connection.AbstractAPIHandler
addQueryFragmentAndNormalize, buildApiURI, buildEndpointURI, buildURI, buildWebSocketURI, delete, executeAsyncWithStreamBody, executeAsyncWithStringBody, executeBinary, executeWithStreamBody, executeWithStringBody, get, getBinary, getConf, getHttpLogger, getHttpRequestTimeout, getMaxRetries, getOrBuildClient, getRequestBuilder, getRootApiURI, getUserAgent, getWebSocketURI, patch, patchBinary, post, postBinary, put, putBinary, send, sendAsync
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface co.arago.hiro.client.connection.token.TokenAPIHandler
buildWebSocketURI, getApiURIOf, getConf, getOrBuildClient, getRootApiURI, getUserAgent, getVersionMap
-
-
-
-
Field Detail
-
apiName
protected final java.lang.String apiName
- See Also:
- Constant Field Values
-
organization
protected java.lang.String organization
-
organizationId
protected java.lang.String organizationId
-
clientId
protected final java.lang.String clientId
-
clientSecret
protected final java.lang.String clientSecret
-
apiPath
protected final java.lang.String apiPath
-
tokenInfo
protected final AbstractRemoteAuthTokenAPIHandler.TokenInfo tokenInfo
-
apiURI
protected java.net.URI apiURI
-
-
Constructor Detail
-
AbstractRemoteAuthTokenAPIHandler
protected AbstractRemoteAuthTokenAPIHandler(AbstractRemoteAuthTokenAPIHandler.Conf<?> builder)
-
-
Method Detail
-
getRefreshOffset
public long getRefreshOffset()
-
setRefreshOffset
public void setRefreshOffset(long refreshOffset)
- Parameters:
refreshOffset- ms of offset for token expiry. This is subtracted from the instant given via "expires-at".
-
getURI
public java.net.URI getURI(java.lang.String path) throws java.io.IOException, java.lang.InterruptedException, HiroExceptionConstruct my URI. This method will query /api/version once to construct the URI unlessapiPathis set.- Parameters:
path- The path to append to the API path.- Returns:
- The URI without query or fragment.
- Throws:
java.io.IOException- On a failed call to /api/versionjava.lang.InterruptedException- Call got interruptedHiroException- When calling /api/version responds with an error
-
tokenExpired
public boolean tokenExpired()
Check for token expiration- Returns:
- true if expired or no token is available, false otherwise.
-
expiryInstant
public java.time.Instant expiryInstant()
Calculate the Instant after which the token should be refreshed (expiresAt minus theAbstractRemoteAuthTokenAPIHandler.TokenInfo.refreshOffset).- Returns:
- The Instant after which the token shall be refreshed. null if token cannot be refreshed.
-
checkResponse
public boolean checkResponse(java.net.http.HttpResponse<java.io.InputStream> httpResponse, int retryCount) throws HiroException, java.io.IOException, java.lang.InterruptedExceptionCheck for the kind of error. 401 throws TokenUnauthorizedException, all other throw AuthenticationTokenException.- Specified by:
checkResponsein interfaceTokenAPIHandler- Overrides:
checkResponsein classAbstractAPIHandler- Parameters:
httpResponse- The httpResponse from the HttpRequestretryCount- current counter for retries- Returns:
- true for retry, false otherwise.
- Throws:
TokenUnauthorizedException- On error 401 immediately.AuthenticationTokenException- On all other status errors when no retries are left.java.io.IOException- When reading the inputStream fails.HiroHttpException- When the statusCode is < 200 or > 399.HiroException- On internal errors regarding hiro data processing.java.lang.InterruptedException- When a call (possibly of an overwritten method) gets interrupted.
-
getToken
public 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.
-
getRefreshToken
public java.lang.String getRefreshToken()
- Returns:
- The refresh token or null if no token data or refresh token exists.
-
requestToken
protected abstract void requestToken(java.lang.String organization, java.lang.String organizationId) throws java.io.IOException, java.lang.InterruptedException, HiroExceptionObtain a new token from the auth API.- Parameters:
organization- : Optional organization name. May be null.organizationId- : Optional organization id. May be null.- Throws:
java.lang.InterruptedException- When call gets interrupted.java.io.IOException- When call has IO errors.HiroException- On Hiro protocol / handling errors.
-
refreshToken
public void refreshToken() throws HiroException, java.io.IOException, java.lang.InterruptedExceptionRefresh an invalid token.Uses the internal values of organization and organizationId if present.
- Throws:
java.lang.InterruptedException- When call gets interrupted.java.io.IOException- When call has IO errors.HiroException- On Hiro protocol / handling errors.
-
refreshToken
public void refreshToken(java.lang.String organization, java.lang.String organizationId) throws java.io.IOException, java.lang.InterruptedException, HiroExceptionRefresh an invalid token.- Parameters:
organization- : Optional organization name. May be null.organizationId- : Optional organization id. May be null.- Throws:
java.lang.InterruptedException- When call gets interrupted.java.io.IOException- When call has IO errors.HiroException- On Hiro protocol / handling errors.
-
revokeToken
public void revokeToken() throws java.io.IOException, java.lang.InterruptedException, HiroExceptionRevoke a token. This only works if a refreshToken is available.- Throws:
java.lang.InterruptedException- When call gets interrupted.java.io.IOException- When call has IO errors.HiroException- On Hiro protocol / handling errors.
-
revokeToken
public void revokeToken(java.lang.String tokenHint) throws java.io.IOException, java.lang.InterruptedException, HiroExceptionRevoke a token.- Parameters:
tokenHint- The type of token to revoke. Valid are "refresh_token" and "access_token".- Throws:
java.lang.InterruptedException- When call gets interrupted.java.io.IOException- When call has IO errors.HiroException- On Hiro protocol / handling errors.TokenUnauthorizedException- When neither access_token nor refresh_token exist.
-
hasToken
public 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
public boolean hasRefreshToken()
Check for existence of a refresh token in the TokenAPIHandler.- Returns:
- true if a refresh token retrieved, false otherwise.
-
-