Package com.ibm.cloud.sdk.core.security
Class IamToken
- java.lang.Object
-
- com.ibm.cloud.sdk.core.security.AbstractToken
-
- com.ibm.cloud.sdk.core.security.IamToken
-
- All Implemented Interfaces:
TokenServerResponse
,ObjectModel
public class IamToken extends AbstractToken implements ObjectModel, TokenServerResponse
Represents response from IAM API.
-
-
Field Summary
Fields Modifier and Type Field Description static long
IamExpirationWindow
-
Constructor Summary
Constructors Constructor Description IamToken()
IamToken(VpcTokenResponse vpcResponse)
Converts a VpcTokenResponse instance to an IamToken instance.IamToken(java.lang.Throwable t)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getAccessToken()
java.lang.Long
getExpiration()
java.lang.Long
getExpiresIn()
java.lang.Long
getRefreshTime()
java.lang.String
getRefreshToken()
java.lang.String
getTokenType()
boolean
isTokenValid()
Check if the currently stored access token is valid.boolean
needsRefresh()
Returns true iff currently stored access token should be refreshed.java.lang.String
toString()
-
Methods inherited from class com.ibm.cloud.sdk.core.security.AbstractToken
getException, setException
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.ibm.cloud.sdk.core.service.model.ObjectModel
equals, hashCode
-
-
-
-
Field Detail
-
IamExpirationWindow
public static final long IamExpirationWindow
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
IamToken
public IamToken()
-
IamToken
public IamToken(java.lang.Throwable t)
-
IamToken
public IamToken(VpcTokenResponse vpcResponse)
Converts a VpcTokenResponse instance to an IamToken instance.- Parameters:
vpcResponse
- the VpcTokenResponse instance to be converted.
-
-
Method Detail
-
getAccessToken
public java.lang.String getAccessToken()
- Specified by:
getAccessToken
in classAbstractToken
-
getRefreshToken
public java.lang.String getRefreshToken()
-
getTokenType
public java.lang.String getTokenType()
-
getExpiresIn
public java.lang.Long getExpiresIn()
-
getExpiration
public java.lang.Long getExpiration()
-
getRefreshTime
public java.lang.Long getRefreshTime()
-
needsRefresh
public boolean needsRefresh()
Returns true iff currently stored access token should be refreshed. This method uses a buffer to prevent the edge case of the token expiring before the request could be made, so this method will return true if the current time is within that buffer. The buffer will be a fraction of the total TTL. Using 80%. This method also updates the expiration time if it determines the token needs 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 valid and not expired
-
toString
public java.lang.String toString()
- Specified by:
toString
in interfaceObjectModel
- Overrides:
toString
in classjava.lang.Object
-
-