Class PasswordAuthTokenAPIHandler

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class PasswordAuthTokenAPIHandler
    extends AbstractTokenAPIHandler
    • Field Detail

      • 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
      • 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".
      • 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,
                                   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.
      • 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.
        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.
        Specified by:
        getToken in class AbstractTokenAPIHandler
        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,
                                    HiroException
        Obtain 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,
                                 HiroException
        Refresh an invalid token.
        Specified by:
        refreshToken in class AbstractTokenAPIHandler
        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,
                                HiroException
        Revoke a token. This only works if a refreshToken is available.
        Specified by:
        revokeToken in class AbstractTokenAPIHandler
        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:
        hasToken in class AbstractTokenAPIHandler
        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:
        hasRefreshToken in class AbstractTokenAPIHandler
        Returns:
        true if a refresh token retrieved, false otherwise.