首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Springsecurity-oauth2之TokenStore

Springsecurity-oauth2之TokenStore

作者头像
克虏伯
发布2019-04-15 09:46:17
发布2019-04-15 09:46:17
7.1K0
举报

    Spring-security-oauth2的版本是2.0。

    TokenStore是个interface,如下List-1

List-1

代码语言:javascript
复制
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

代码语言:javascript
复制
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比其它的稍微复杂点。

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档