Springsecurity-oauth2之TokenStore

    Spring-security-oauth2的版本是2.0。

    TokenStore是个interface,如下List-1

    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中)。

    TokenStore的实现类,有InMemoryTokenStore、JdbcTokenStore、JwkTokenStore、RedisTokenStore。

    InMemoryTokenStore将OAuth2AccessToken保存在内存中,它有很多的ConcurrentHashMap属性。

    JdbcTokenStore将OAuth2AccessToken保存在数据库中,其构造方法需要DataSource,用于构造JdbcTemplate,通过JdbcTemplate来操作数据库。

 RedisTokenStore将OAuth2AccessToken保存到Reis中,构造方法需要RedisConnectionFactory,之后通过Connection操作Redis。

    JwtTokenStore,如下List-2所示

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

转载于:https://my.oschina.net/u/2518341/blog/3014247

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值