Spring-security-oauth2的版本是2.0。java
TokenStore是個interface,以下List-1spring
List-1數據庫
package org.springframework.security.oauth2.provider.token; import java.util.Collection; import org.springframework.security.oauth2.common.OAuth2AccessToken; import org.springframework.security.oauth2.common.OAuth2RefreshToken; import org.springframework.security.oauth2.provider.OAuth2Authentication; /** * Persistence interface for OAuth2 tokens. */ public interface TokenStore { /** * Read the authentication stored under the specified token value. * * @param token The token value under which the authentication is stored. * @return The authentication, or null if none. */ OAuth2Authentication readAuthentication(OAuth2AccessToken token); /** * Read the authentication stored under the specified token value. * * @param token The token value under which the authentication is stored. * @return The authentication, or null if none. */ OAuth2Authentication readAuthentication(String token); ......
它就是用來保存token(封裝在OAuth2AccessToken中)。app
TokenStore的實現類,有InMemoryTokenStore、JdbcTokenStore、JwkTokenStore、RedisTokenStore。ide
InMemoryTokenStore將OAuth2AccessToken保存在內存中,它有不少的ConcurrentHashMap屬性。this
JdbcTokenStore將OAuth2AccessToken保存在數據庫中,其構造方法須要DataSource,用於構造JdbcTemplate,經過JdbcTemplate來操做數據庫。code
RedisTokenStore將OAuth2AccessToken保存到Reis中,構造方法須要RedisConnectionFactory,以後經過Connection操做Redis。jwt
JwtTokenStore,以下List-2所示token
List-2內存
public class JwtTokenStore implements TokenStore { private JwtAccessTokenConverter jwtTokenEnhancer; private ApprovalStore approvalStore; /** * Create a JwtTokenStore with this token enhancer (should be shared with the DefaultTokenServices if used). * * @param jwtTokenEnhancer */ public JwtTokenStore(JwtAccessTokenConverter jwtTokenEnhancer) { this.jwtTokenEnhancer = jwtTokenEnhancer; } ......
JwtTokenStore比其它的稍微複雜點。