Package com.ibm.cloud.sdk.core.security
Class MCSPToken
- java.lang.Object
-
- com.ibm.cloud.sdk.core.security.AbstractToken
-
- com.ibm.cloud.sdk.core.security.MCSPToken
-
public class MCSPToken extends AbstractToken
This class holds the cached information related to an access token received by the Multi-Cloud Saas Platform (MCSP) Authenticator.
-
-
Constructor Summary
Constructors Constructor Description MCSPToken()
MCSPToken(MCSPTokenResponse response)
This ctor will extract the access token from the specified MCSPTokenResponse instance, and compute the refresh time as "80% of the timeToLive added to the issued-at time".MCSPToken(java.lang.String accessToken)
This ctor is used to store a user-managed access token which will never expire.MCSPToken(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 com.ibm.cloud.sdk.core.security.AbstractToken
getException, setException
-
-
-
-
Constructor Detail
-
MCSPToken
public MCSPToken()
-
MCSPToken
public MCSPToken(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
-
MCSPToken
public MCSPToken(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
-
MCSPToken
public MCSPToken(MCSPTokenResponse response)
This ctor will extract the access token from the specified MCSPTokenResponse 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 MCSPTokenResponse 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 to be refreshed to prevent other threads from making multiple refresh calls.- Specified by:
needsRefresh
in classAbstractToken
- 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 classAbstractToken
- Returns:
- true iff the current access token is not expired
-
getAccessToken
public java.lang.String getAccessToken()
- Specified by:
getAccessToken
in classAbstractToken
- Returns:
- the access token value from this
-
-