解决oauth_access_token表出现一个UserName有多条数据异常

在spring-oauth-server的ISSUE #IAI2E#IP5N9中提到的oauth_access_token表会出现多条相同username的数据的异常情况,

解决办法如下:

1.对 oauth_access_token 表的authentication_id 字段增加唯一索引,创建索引SQL如下:

ALTER TABLE oauth_access_token ADD UNIQUE INDEX authentication_id_unique_index(authentication_id);

若是新建数据库,则直接按照 spring-oauth-server开发要求运行SQL文件(initial_db.ddl)即可(创建表的SQL中已经加了唯一索引)

 

2.推荐使用将access token 数据存入redis来提升性能与解决此问题,详细请访问 http://andaily.com/blog/?p=19776

 

在spring-oauth-server中将AccessToken存入Redis的配置

为了满足高性能的要求,spring-oauth-server中增加了使用redis存储 AccessToken的功能,以达到更高的性能要求。

以下配置是将AccessToken存入Redis的参考步骤。

前提:使用spring-oauth-server的config分支,并已经安装Redis服务

 

1.pom.xml中增加spring-boot的redis dependency.

redis-pom

 

2.application.properties中增加redis的配置属性

redis-prop

 

3.配置OAuth2中TokenStore的Redis实现:RedisTokenStore

config

(prefix值 可根据实际需要进行修改;默认的实现使用JdbcTokenStore)

 

在以上配置完成后,启动redis服务,并将spring-oauth-server重启后,即完成了将AccessToken配置存入Redis的功能,

测试获取AccessToken后,可在redis中查看到对应的数据,如下所示:

redis-log

 

spring-oauth-server的redis配置代码分支:https://gitee.com/shengzhao/spring-oauth-server/tree/config-redis/