Class Cp4dToken


  • public class Cp4dToken
    extends AbstractToken
    This class holds relevant info re: a CP4D access token for use by the CloudPakForDataAuthenticator class.
    • Constructor Summary

      Constructors 
      Constructor Description
      Cp4dToken()  
      Cp4dToken​(Cp4dServiceInstanceTokenResponse response)
      This ctor will extract the ICP4D access token from the specified Cp4dTokenResponse instance, and compute the refresh time as "80% of the timeToLive added to the issued-at time".
      Cp4dToken​(Cp4dTokenResponse response)
      This ctor will extract the ICP4D access token from the specified Cp4dTokenResponse instance, and compute the refresh time as "80% of the timeToLive added to the issued-at time".
      Cp4dToken​(java.lang.String accessToken)
      This ctor is used to store a user-managed access token which will never expire.
      Cp4dToken​(java.lang.Throwable t)
      This ctor is used to store an exception which indicates an error with the most recent token server interaction.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getAccessToken()  
      boolean isTokenValid()
      Check if the currently stored access token is valid.
      boolean needsRefresh()
      Returns true iff this object does not hold a valid access token or has one which has crossed our refresh time.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Cp4dToken

        public Cp4dToken()
      • Cp4dToken

        public Cp4dToken​(java.lang.String accessToken)
        This ctor is used to store a user-managed access token which will never expire.
        Parameters:
        accessToken - the user-managed access token
      • Cp4dToken

        public Cp4dToken​(java.lang.Throwable t)
        This ctor is used to store an exception which indicates an error with the most recent token server interaction.
        Parameters:
        t - the exception to store in this object
      • Cp4dToken

        public Cp4dToken​(Cp4dTokenResponse response)
        This ctor will extract the ICP4D access token from the specified Cp4dTokenResponse instance, and compute the refresh time as "80% of the timeToLive added to the issued-at time". This means that we'll trigger the acquisition of a new token shortly before it is set to expire.
        Parameters:
        response - the Cp4dTokenResponse instance
      • Cp4dToken

        public Cp4dToken​(Cp4dServiceInstanceTokenResponse response)
        This ctor will extract the ICP4D access token from the specified Cp4dTokenResponse instance, and compute the refresh time as "80% of the timeToLive added to the issued-at time". This means that we'll trigger the acquisition of a new token shortly before it is set to expire.
        Parameters:
        response - the Cp4dTokenResponse instance
    • Method Detail

      • needsRefresh

        public boolean needsRefresh()
        Returns true iff this object does not hold a valid access token or has one which has crossed our refresh time. This method also updates the refresh time if it determines the token needs refreshed to prevent other threads from making multiple refresh calls.
        Specified by:
        needsRefresh in class AbstractToken
        Returns:
        true if token is invalid or past the refresh time, false otherwise
      • isTokenValid

        public boolean isTokenValid()
        Check if the currently stored access token is valid. This is different from the needsRefresh method in that it uses the actual TTL to calculate the expiration, rather than just a fraction.
        Specified by:
        isTokenValid in class AbstractToken
        Returns:
        true iff is the current access token is not expired
      • getAccessToken

        public java.lang.String getAccessToken()
        Specified by:
        getAccessToken in class AbstractToken
        Returns:
        the access token value from this