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

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

public class JdbcTokenStore
extends Object
implements TokenStore

Implementation of token services that stores tokens in a database.

Author:
Ken Dombeck, Luke Taylor, Dave Syer

Constructor Summary
JdbcTokenStore(DataSource dataSource)
           
 
Method Summary
protected  OAuth2AccessToken deserializeAccessToken(byte[] token)
           
protected  OAuth2Authentication deserializeAuthentication(byte[] authentication)
           
protected  OAuth2RefreshToken deserializeRefreshToken(byte[] token)
           
protected  String extractTokenKey(String value)
           
 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.
 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 value)
           
 OAuth2RefreshToken readRefreshToken(String token)
          Read a refresh token from the store.
 void removeAccessToken(OAuth2AccessToken token)
          Remove an access token from the database.
 void removeAccessToken(String tokenValue)
           
 void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken)
          Remove an access token using a refresh token.
 void removeAccessTokenUsingRefreshToken(String refreshToken)
           
 void removeRefreshToken(OAuth2RefreshToken token)
          Remove a refresh token from the database.
 void removeRefreshToken(String token)
           
protected  byte[] serializeAccessToken(OAuth2AccessToken token)
           
protected  byte[] serializeAuthentication(OAuth2Authentication authentication)
           
protected  byte[] serializeRefreshToken(OAuth2RefreshToken token)
           
 void setAuthenticationKeyGenerator(AuthenticationKeyGenerator authenticationKeyGenerator)
           
 void setDeleteAccessTokenFromRefreshTokenSql(String deleteAccessTokenFromRefreshTokenSql)
           
 void setDeleteAccessTokenSql(String deleteAccessTokenSql)
           
 void setDeleteRefreshTokenSql(String deleteRefreshTokenSql)
           
 void setInsertAccessTokenSql(String insertAccessTokenSql)
           
 void setInsertRefreshTokenSql(String insertRefreshTokenSql)
           
 void setSelectAccessTokenAuthenticationSql(String selectAccessTokenAuthenticationSql)
           
 void setSelectAccessTokenFromAuthenticationSql(String selectAccessTokenFromAuthenticationSql)
           
 void setSelectAccessTokenSql(String selectAccessTokenSql)
           
 void setSelectRefreshTokenAuthenticationSql(String selectRefreshTokenAuthenticationSql)
           
 void setSelectRefreshTokenSql(String selectRefreshTokenSql)
           
 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

JdbcTokenStore

public JdbcTokenStore(DataSource dataSource)
Method Detail

setAuthenticationKeyGenerator

public void setAuthenticationKeyGenerator(AuthenticationKeyGenerator authenticationKeyGenerator)

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

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.

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(OAuth2AccessToken token)
Description copied from interface: TokenStore
Remove an access token from the database.

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

removeAccessToken

public void removeAccessToken(String tokenValue)

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.

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 token)
Description copied from interface: TokenStore
Read a refresh token from the store.

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

removeRefreshToken

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

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

removeRefreshToken

public void removeRefreshToken(String token)

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 value)

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.

removeAccessTokenUsingRefreshToken

public void removeAccessTokenUsingRefreshToken(String refreshToken)

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

extractTokenKey

protected String extractTokenKey(String value)

serializeAccessToken

protected byte[] serializeAccessToken(OAuth2AccessToken token)

serializeRefreshToken

protected byte[] serializeRefreshToken(OAuth2RefreshToken token)

serializeAuthentication

protected byte[] serializeAuthentication(OAuth2Authentication authentication)

deserializeAccessToken

protected OAuth2AccessToken deserializeAccessToken(byte[] token)

deserializeRefreshToken

protected OAuth2RefreshToken deserializeRefreshToken(byte[] token)

deserializeAuthentication

protected OAuth2Authentication deserializeAuthentication(byte[] authentication)

setInsertAccessTokenSql

public void setInsertAccessTokenSql(String insertAccessTokenSql)

setSelectAccessTokenSql

public void setSelectAccessTokenSql(String selectAccessTokenSql)

setDeleteAccessTokenSql

public void setDeleteAccessTokenSql(String deleteAccessTokenSql)

setInsertRefreshTokenSql

public void setInsertRefreshTokenSql(String insertRefreshTokenSql)

setSelectRefreshTokenSql

public void setSelectRefreshTokenSql(String selectRefreshTokenSql)

setDeleteRefreshTokenSql

public void setDeleteRefreshTokenSql(String deleteRefreshTokenSql)

setSelectAccessTokenAuthenticationSql

public void setSelectAccessTokenAuthenticationSql(String selectAccessTokenAuthenticationSql)

setSelectRefreshTokenAuthenticationSql

public void setSelectRefreshTokenAuthenticationSql(String selectRefreshTokenAuthenticationSql)

setSelectAccessTokenFromAuthenticationSql

public void setSelectAccessTokenFromAuthenticationSql(String selectAccessTokenFromAuthenticationSql)

setDeleteAccessTokenFromRefreshTokenSql

public void setDeleteAccessTokenFromRefreshTokenSql(String deleteAccessTokenFromRefreshTokenSql)


Copyright © 2012. All Rights Reserved.