Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kou | zhao
micro-service-skeleton
提交
61cfbc54
M
micro-service-skeleton
项目概览
kou | zhao
/
micro-service-skeleton
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
micro-service-skeleton
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
61cfbc54
编写于
12月 29, 2017
作者:
M
ManongJu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
使用redis存储Token信息,更为接近生产环境
上级
b036c99c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
6 deletion
+17
-6
auth-center/src/main/java/com/microservice/skeleton/auth/config/AuthorizationServerConfig.java
...rvice/skeleton/auth/config/AuthorizationServerConfig.java
+17
-6
未找到文件。
auth-center/src/main/java/com/microservice/skeleton/auth/config/AuthorizationServerConfig.java
浏览文件 @
61cfbc54
...
@@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.security.authentication.AuthenticationManager
;
import
org.springframework.security.authentication.AuthenticationManager
;
import
org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer
;
import
org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer
;
import
org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter
;
import
org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter
;
...
@@ -15,9 +16,9 @@ import org.springframework.security.oauth2.provider.ClientDetailsService;
...
@@ -15,9 +16,9 @@ import org.springframework.security.oauth2.provider.ClientDetailsService;
import
org.springframework.security.oauth2.provider.client.JdbcClientDetailsService
;
import
org.springframework.security.oauth2.provider.client.JdbcClientDetailsService
;
import
org.springframework.security.oauth2.provider.token.DefaultTokenServices
;
import
org.springframework.security.oauth2.provider.token.DefaultTokenServices
;
import
org.springframework.security.oauth2.provider.token.store.JdbcTokenStore
;
import
org.springframework.security.oauth2.provider.token.store.JdbcTokenStore
;
import
org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* Created by Mr.Yangxiufeng on 2017/12/28.
* Created by Mr.Yangxiufeng on 2017/12/28.
...
@@ -36,11 +37,20 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
...
@@ -36,11 +37,20 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
@Autowired
@Autowired
private
UserDetailsServiceImpl
userDetailsService
;
private
UserDetailsServiceImpl
userDetailsService
;
@Autowired
private
RedisConnectionFactory
redisConnectionFactory
;
@Bean
@Bean
public
JdbcTokenStore
jdbc
TokenStore
(){
RedisTokenStore
redis
TokenStore
(){
return
new
JdbcTokenStore
(
dataSource
);
return
new
RedisTokenStore
(
redisConnectionFactory
);
}
}
//token存储数据库
// @Bean
// public JdbcTokenStore jdbcTokenStore(){
// return new JdbcTokenStore(dataSource);
// }
@Override
@Override
public
void
configure
(
ClientDetailsServiceConfigurer
clients
)
throws
Exception
{
public
void
configure
(
ClientDetailsServiceConfigurer
clients
)
throws
Exception
{
clients
.
withClientDetails
(
clientDetails
());
clients
.
withClientDetails
(
clientDetails
());
...
@@ -51,7 +61,7 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
...
@@ -51,7 +61,7 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
}
}
@Override
@Override
public
void
configure
(
AuthorizationServerEndpointsConfigurer
endpoints
)
throws
Exception
{
public
void
configure
(
AuthorizationServerEndpointsConfigurer
endpoints
)
throws
Exception
{
endpoints
.
tokenStore
(
jdbc
TokenStore
())
endpoints
.
tokenStore
(
redis
TokenStore
())
.
userDetailsService
(
userDetailsService
)
.
userDetailsService
(
userDetailsService
)
.
authenticationManager
(
authenticationManager
);
.
authenticationManager
(
authenticationManager
);
endpoints
.
tokenServices
(
defaultTokenServices
());
endpoints
.
tokenServices
(
defaultTokenServices
());
...
@@ -65,10 +75,11 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
...
@@ -65,10 +75,11 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
@Bean
@Bean
public
DefaultTokenServices
defaultTokenServices
(){
public
DefaultTokenServices
defaultTokenServices
(){
DefaultTokenServices
tokenServices
=
new
DefaultTokenServices
();
DefaultTokenServices
tokenServices
=
new
DefaultTokenServices
();
tokenServices
.
setTokenStore
(
jdbc
TokenStore
());
tokenServices
.
setTokenStore
(
redis
TokenStore
());
tokenServices
.
setSupportRefreshToken
(
true
);
tokenServices
.
setSupportRefreshToken
(
true
);
tokenServices
.
setClientDetailsService
(
clientDetails
());
tokenServices
.
setClientDetailsService
(
clientDetails
());
// tokenServices.setAccessTokenValiditySeconds( (int) TimeUnit.DAYS.toSeconds(30)); // token有效期自定义设置,默认12小时
tokenServices
.
setAccessTokenValiditySeconds
(
60
);
// token有效期自定义设置,默认12小时
tokenServices
.
setRefreshTokenValiditySeconds
(
60
*
60
*
24
*
30
);
//默认30天,这里修改
return
tokenServices
;
return
tokenServices
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录