org.jets3t.service.security
Class OAuth2Tokens

java.lang.Object
  extended by org.jets3t.service.security.OAuth2Tokens

public class OAuth2Tokens
extends java.lang.Object

Represent OAuth 2.0 access and refresh tokens, and an optional expiry date based on the expiry timeout an OAuth end-point may return.


Field Summary
protected  java.lang.String accessToken
           
protected  java.util.Date expiry
           
protected  java.lang.String refreshToken
           
 
Constructor Summary
OAuth2Tokens(java.lang.String accessToken, java.lang.String refreshToken)
          Store token data without the expiry date of the access token.
OAuth2Tokens(java.lang.String accessToken, java.lang.String refreshToken, java.util.Date expiry)
          Store token data including the expiry date of the access token.
 
Method Summary
static java.util.Date calculateExpiry(java.lang.Number expiresInSeconds)
          Calculate a date timestamp a given number of seconds in the future.
 void expireAccessToken()
          Forcibly expire the access token by setting the expiry timestamp to the epoch.
 java.lang.String getAccessToken()
           
 java.util.Date getExpiry()
           
 java.lang.String getRefreshToken()
           
 boolean isAccessTokenExpired()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

accessToken

protected final java.lang.String accessToken

refreshToken

protected final java.lang.String refreshToken

expiry

protected java.util.Date expiry
Constructor Detail

OAuth2Tokens

public OAuth2Tokens(java.lang.String accessToken,
                    java.lang.String refreshToken,
                    java.util.Date expiry)
Store token data including the expiry date of the access token.

Parameters:
accessToken -
refreshToken -
expiry -

OAuth2Tokens

public OAuth2Tokens(java.lang.String accessToken,
                    java.lang.String refreshToken)
Store token data without the expiry date of the access token.

Parameters:
accessToken -
refreshToken -
Method Detail

getAccessToken

public java.lang.String getAccessToken()

getRefreshToken

public java.lang.String getRefreshToken()

getExpiry

public java.util.Date getExpiry()

expireAccessToken

public void expireAccessToken()
Forcibly expire the access token by setting the expiry timestamp to the epoch.


isAccessTokenExpired

public boolean isAccessTokenExpired()
Returns:
true if the access token as expired according to the expiry date provided when this class was created, false otherwise. Note that this method will always return true if no expiry date was provided (i.e. getExpiry() is null) since the expiry time is unknown.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

calculateExpiry

public static java.util.Date calculateExpiry(java.lang.Number expiresInSeconds)
Calculate a date timestamp a given number of seconds in the future. This is convenient for calculating the expiry time for OAuth access tokens when you are only given the "expires_in" timeout value by the OAuth service.

Parameters:
expiresInSeconds - how many seconds in the future the result should be. May be null, in which case the current date/time is returned.
Returns:
a Date at the current time, or a given number of seconds in the future.