org.springframework.security.oauth2.provider.token
Class InMemoryTokenStore

java.lang.Object
  extended by org.springframework.security.oauth2.provider.token.InMemoryTokenStore
All Implemented Interfaces:
TokenStore

public class InMemoryTokenStore
extends Object
implements TokenStore

Implementation of token services that stores tokens in memory.

Author:
Ryan Heaton, Luke Taylor, Dave Syer

Constructor Summary
InMemoryTokenStore()
           
 
Method Summary
 void clear()
          Convenience method for super admin users to remove all tokens (useful for testing, not really in production)
 Collection<OAuth2AccessToken> findTokensByClientId(String clientId)
           
 Collection<OAuth2AccessToken> findTokensByUserName(String userName)
           
 OAuth2AccessToken getAccessToken(OAuth2Authentication authentication)
          Retrieve an access token stored against the provided authentication key, if it exists.
 int getAccessTokenCount()
           
 int getExpiryTokenCount()
           
 int getFlushInterval()
          The interval (count of token inserts) between flushing expired tokens.
 int getRefreshTokenCount()
           
 OAuth2AccessToken readAccessToken(String tokenValue)
          Read an access token from the store.
 OAuth2Authentication readAuthentication(OAuth2AccessToken token)
          Read the authentication stored under the specified token value.
 OAuth2Authentication readAuthentication(String token)
          Read the authentication stored under the specified token value.
 OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token)
           
 OAuth2Authentication readAuthenticationForRefreshToken(String token)
           
 OAuth2RefreshToken readRefreshToken(String tokenValue)
          Read a refresh token from the store.
 void removeAccessToken(OAuth2AccessToken accessToken)
          Remove an access token from the database.
 void removeAccessToken(String tokenValue)
           
 void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken)
          Remove an access token using a refresh token.
 void removeRefreshToken(OAuth2RefreshToken refreshToken)
          Remove a refresh token from the database.
 void removeRefreshToken(String tokenValue)
           
 void setAuthenticationKeyGenerator(AuthenticationKeyGenerator authenticationKeyGenerator)
           
 void setFlushInterval(int flushInterval)
          The number of tokens to store before flushing expired tokens.
 void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication)
          Store an access token.
 void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication)
          Store the specified refresh token in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InMemoryTokenStore

public InMemoryTokenStore()
Method Detail

setFlushInterval

public void setFlushInterval(int flushInterval)
The number of tokens to store before flushing expired tokens. Defaults to 1000.

Parameters:
flushInterval - the interval to set

getFlushInterval

public int getFlushInterval()
The interval (count of token inserts) between flushing expired tokens.

Returns:
the flushInterval the flush interval

clear

public void clear()
Convenience method for super admin users to remove all tokens (useful for testing, not really in production)


setAuthenticationKeyGenerator

public void setAuthenticationKeyGenerator(AuthenticationKeyGenerator authenticationKeyGenerator)

getAccessTokenCount

public int getAccessTokenCount()

getRefreshTokenCount

public int getRefreshTokenCount()

getExpiryTokenCount

public int getExpiryTokenCount()

getAccessToken

public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication)
Description copied from interface: TokenStore
Retrieve an access token stored against the provided authentication key, if it exists.

Specified by:
getAccessToken in interface TokenStore
Parameters:
authentication - the authentication key for the access token
Returns:
the access token or null if there was none

readAuthentication

public OAuth2Authentication readAuthentication(OAuth2AccessToken token)
Description copied from interface: TokenStore
Read the authentication stored under the specified token value.

Specified by:
readAuthentication in interface TokenStore
Parameters:
token - The token value under which the authentication is stored.
Returns:
The authentication, or null if none.

readAuthentication

public OAuth2Authentication readAuthentication(String token)
Description copied from interface: TokenStore
Read the authentication stored under the specified token value.

Specified by:
readAuthentication in interface TokenStore
Parameters:
token - The token value under which the authentication is stored.
Returns:
The authentication, or null if none.

readAuthenticationForRefreshToken

public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token)
Specified by:
readAuthenticationForRefreshToken in interface TokenStore
Parameters:
token - a refresh token
Returns:
the authentication originally used to grant the refresh token

readAuthenticationForRefreshToken

public OAuth2Authentication readAuthenticationForRefreshToken(String token)

storeAccessToken

public void storeAccessToken(OAuth2AccessToken token,
                             OAuth2Authentication authentication)
Description copied from interface: TokenStore
Store an access token.

Specified by:
storeAccessToken in interface TokenStore
Parameters:
token - The token to store.
authentication - The authentication associated with the token.

removeAccessToken

public void removeAccessToken(OAuth2AccessToken accessToken)
Description copied from interface: TokenStore
Remove an access token from the database.

Specified by:
removeAccessToken in interface TokenStore
Parameters:
accessToken - The token to remove from the database.

readAccessToken

public OAuth2AccessToken readAccessToken(String tokenValue)
Description copied from interface: TokenStore
Read an access token from the store.

Specified by:
readAccessToken in interface TokenStore
Parameters:
tokenValue - The token value.
Returns:
The access token to read.

removeAccessToken

public void removeAccessToken(String tokenValue)

storeRefreshToken

public void storeRefreshToken(OAuth2RefreshToken refreshToken,
                              OAuth2Authentication authentication)
Description copied from interface: TokenStore
Store the specified refresh token in the database.

Specified by:
storeRefreshToken in interface TokenStore
Parameters:
refreshToken - The refresh token to store.
authentication - The authentication associated with the refresh token.

readRefreshToken

public OAuth2RefreshToken readRefreshToken(String tokenValue)
Description copied from interface: TokenStore
Read a refresh token from the store.

Specified by:
readRefreshToken in interface TokenStore
Parameters:
tokenValue - The value of the token to read.
Returns:
The token.

removeRefreshToken

public void removeRefreshToken(OAuth2RefreshToken refreshToken)
Description copied from interface: TokenStore
Remove a refresh token from the database.

Specified by:
removeRefreshToken in interface TokenStore
Parameters:
refreshToken - The token to remove from the database.

removeRefreshToken

public void removeRefreshToken(String tokenValue)

removeAccessTokenUsingRefreshToken

public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken)
Description copied from interface: TokenStore
Remove an access token using a refresh token. This functionality is necessary so refresh tokens can't be used to create an unlimited number of access tokens.

Specified by:
removeAccessTokenUsingRefreshToken in interface TokenStore
Parameters:
refreshToken - The refresh token.

findTokensByClientId

public Collection<OAuth2AccessToken> findTokensByClientId(String clientId)
Specified by:
findTokensByClientId in interface TokenStore
Parameters:
clientId - the client id
Returns:
a collection of access tokens

findTokensByUserName

public Collection<OAuth2AccessToken> findTokensByUserName(String userName)
Specified by:
findTokensByUserName in interface TokenStore
Parameters:
userName - the user name to search
Returns:
a collection of access tokens


Copyright © 2012. All Rights Reserved.