Class PasswordAuthTokenAPIHandler
- java.lang.Object
-
- co.arago.util.validation.RequiredFieldChecks
-
- co.arago.hiro.client.connection.AbstractAPIHandler
-
- co.arago.hiro.client.connection.AbstractClientAPIHandler
-
- co.arago.hiro.client.connection.AbstractVersionAPIHandler
-
- co.arago.hiro.client.connection.token.AbstractTokenAPIHandler
-
- co.arago.hiro.client.connection.token.PasswordAuthTokenAPIHandler
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class PasswordAuthTokenAPIHandler extends AbstractTokenAPIHandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPasswordAuthTokenAPIHandler.Builderstatic classPasswordAuthTokenAPIHandler.Conf<T extends PasswordAuthTokenAPIHandler.Conf<T>>protected static classPasswordAuthTokenAPIHandler.TokenInfoExtends the TokenResponse with additional data and operations.-
Nested classes/interfaces inherited from class co.arago.hiro.client.connection.AbstractClientAPIHandler
AbstractClientAPIHandler.ProxySpec
-
Nested classes/interfaces inherited from class co.arago.hiro.client.connection.AbstractAPIHandler
AbstractAPIHandler.GetterConf
-
-
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.Stringpasswordprotected PasswordAuthTokenAPIHandler.TokenInfotokenInfoprotected java.lang.Stringusername-
Fields inherited from class co.arago.hiro.client.connection.AbstractClientAPIHandler
connectTimeout, externalHttpClient, followRedirects, httpClient, httpLogger, maxConnectionPool, proxy, sslContext, sslParameters
-
Fields inherited from class co.arago.hiro.client.connection.AbstractAPIHandler
apiUrl, httpRequestTimeout, maxRetries, title, userAgent, version, webSocketUri
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedPasswordAuthTokenAPIHandler(PasswordAuthTokenAPIHandler.Conf<?> builder)
-
Method Summary
All Methods Static Methods Instance 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 thePasswordAuthTokenAPIHandler.TokenInfo.refreshOffset).longgetRefreshOffset()longgetRefreshPause()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.static PasswordAuthTokenAPIHandler.Conf<?>newBuilder()voidrefreshToken()Refresh an invalid token.protected voidrequestToken()Obtain a new token from the auth API.voidrevokeToken()Revoke a token.voidsetRefreshOffset(long refreshOffset)voidsetRefreshPause(long refreshPause)booleantokenExpired()Check for token expirationbooleantokenFresh()Check, whether the token has been renewed within the lastPasswordAuthTokenAPIHandler.TokenInfo.refreshPausems.-
Methods inherited from class co.arago.hiro.client.connection.token.AbstractTokenAPIHandler
addToHeaders
-
Methods inherited from class co.arago.hiro.client.connection.AbstractVersionAPIHandler
getApiUriOf, getVersionMap, requestVersionMap
-
Methods inherited from class co.arago.hiro.client.connection.AbstractClientAPIHandler
close, getHttpLogger, getOrBuildClient
-
Methods inherited from class co.arago.hiro.client.connection.AbstractAPIHandler
addQueryAndFragment, buildApiURI, buildEndpointURI, buildURI, buildWebSocketURI, delete, executeAsyncWithStreamBody, executeAsyncWithStringBody, executeBinary, executeWithStreamBody, executeWithStringBody, get, getApiUrl, getBinary, getHttpRequestTimeout, getMaxRetries, getRequestBuilder, getUserAgent, getWebSocketUri, patch, patchBinary, post, postBinary, put, putBinary, send, sendAsync
-
-
-
-
Field Detail
-
apiName
protected final java.lang.String apiName
- See Also:
- Constant Field Values
-
username
protected final java.lang.String username
-
password
protected final java.lang.String password
-
clientId
protected final java.lang.String clientId
-
clientSecret
protected final java.lang.String clientSecret
-
apiPath
protected final java.lang.String apiPath
-
tokenInfo
protected final PasswordAuthTokenAPIHandler.TokenInfo tokenInfo
-
apiUri
protected java.net.URI apiUri
-
-
Constructor Detail
-
PasswordAuthTokenAPIHandler
protected PasswordAuthTokenAPIHandler(PasswordAuthTokenAPIHandler.Conf<?> builder)
-
-
Method Detail
-
newBuilder
public static PasswordAuthTokenAPIHandler.Conf<?> newBuilder()
-
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".
-
getRefreshPause
public long getRefreshPause()
-
setRefreshPause
public void setRefreshPause(long refreshPause)
- Parameters:
refreshPause- ms of time, where no refresh calls are sent to the backend to avoid request flooding
-
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.
-
tokenFresh
public boolean tokenFresh()
Check, whether the token has been renewed within the lastPasswordAuthTokenAPIHandler.TokenInfo.refreshPausems.- Returns:
- true if within the timespan, false otherwise.
-
expiryInstant
public java.time.Instant expiryInstant()
Calculate the Instant after which the token should be refreshed (expiresAt minus thePasswordAuthTokenAPIHandler.TokenInfo.refreshOffset).- Specified by:
expiryInstantin classAbstractTokenAPIHandler- 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.- 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.- Specified by:
getTokenin classAbstractTokenAPIHandler- 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.
-
requestToken
protected void requestToken() throws java.io.IOException, java.lang.InterruptedException, HiroExceptionObtain a new token from the auth API.- 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 java.io.IOException, java.lang.InterruptedException, HiroExceptionRefresh an invalid token.- Specified by:
refreshTokenin classAbstractTokenAPIHandler- Throws:
java.io.IOException- When call has IO errors.java.lang.InterruptedException- When call gets interrupted.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.- Specified by:
revokeTokenin classAbstractTokenAPIHandler- Throws:
java.io.IOException- When call has IO errors.java.lang.InterruptedException- When call gets interrupted.HiroException- On Hiro protocol / handling errors.
-
hasToken
public boolean hasToken()
Check for existence of a token in the TokenAPIHandler.- Specified by:
hasTokenin classAbstractTokenAPIHandler- 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.- Specified by:
hasRefreshTokenin classAbstractTokenAPIHandler- Returns:
- true if a refresh token retrieved, false otherwise.
-
-