Class AbstractRemoteAuthTokenAPIHandler

    • Field Detail

      • 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
      • apiURI

        protected java.net.URI apiURI
    • 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,
                                   HiroException
        Construct my URI. This method will query /api/version once to construct the URI unless apiPath is 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/version
        java.lang.InterruptedException - Call got interrupted
        HiroException - 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 the AbstractRemoteAuthTokenAPIHandler.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.InterruptedException
        Check for the kind of error. 401 throws TokenUnauthorizedException, all other throw AuthenticationTokenException.
        Specified by:
        checkResponse in interface TokenAPIHandler
        Overrides:
        checkResponse in class AbstractAPIHandler
        Parameters:
        httpResponse - The httpResponse from the HttpRequest
        retryCount - 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,
                                         HiroException
        Return 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,
                                             HiroException
        Obtain 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.InterruptedException
        Refresh 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,
                                 HiroException
        Refresh 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,
                                HiroException
        Revoke 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,
                                HiroException
        Revoke 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.