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比其它的稍微复杂点。