Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
microservices-platform
提交
79ca39ff
microservices-platform
项目概览
zhangjian1949
/
microservices-platform
与 Fork 源项目一致
Fork自
zlt2000 / microservices-platform
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
microservices-platform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
79ca39ff
编写于
10月 04, 2020
作者:
zlt2000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复redis序列化问题
上级
8c34b8e8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
61 addition
and
15 deletion
+61
-15
zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java
...va/com/central/common/redis/template/RedisRepository.java
+42
-6
zlt-doc/sql/user-center.sql
zlt-doc/sql/user-center.sql
+1
-1
zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisAuthorizationCodeServices.java
...al/oauth/service/impl/RedisAuthorizationCodeServices.java
+15
-7
zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisTokensServiceImpl.java
...om/central/oauth/service/impl/RedisTokensServiceImpl.java
+3
-1
未找到文件。
zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java
浏览文件 @
79ca39ff
package
com.central.common.redis.template
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.data.redis.connection.RedisClusterNode
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.connection.RedisServerCommands
;
import
org.springframework.data.redis.core.HashOperations
;
import
org.springframework.data.redis.core.ListOperations
;
import
org.springframework.data.redis.core.RedisCallback
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.*
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
org.springframework.data.redis.serializer.SerializationUtils
;
import
org.springframework.util.Assert
;
...
...
@@ -77,10 +76,40 @@ public class RedisRepository {
*
* @param key redis主键
* @param value 值
* @param time 过期时间(单位秒)
* @param time 过期时间
* @param timeUnit 过期时间单位
*/
public
void
setExpire
(
final
String
key
,
final
Object
value
,
final
long
time
,
final
TimeUnit
timeUnit
)
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
,
time
,
timeUnit
);
}
public
void
setExpire
(
final
String
key
,
final
Object
value
,
final
long
time
)
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
,
time
,
TimeUnit
.
SECONDS
);
this
.
setExpire
(
key
,
value
,
time
,
TimeUnit
.
SECONDS
);
}
public
void
setExpire
(
final
String
key
,
final
Object
value
,
final
long
time
,
final
TimeUnit
timeUnit
,
RedisSerializer
<
Object
>
valueSerializer
)
{
byte
[]
rawKey
=
rawKey
(
key
);
byte
[]
rawValue
=
rawValue
(
value
,
valueSerializer
);
redisTemplate
.
execute
(
new
RedisCallback
<
Object
>()
{
@Override
public
Object
doInRedis
(
RedisConnection
connection
)
throws
DataAccessException
{
potentiallyUsePsetEx
(
connection
);
return
null
;
}
public
void
potentiallyUsePsetEx
(
RedisConnection
connection
)
{
if
(!
TimeUnit
.
MILLISECONDS
.
equals
(
timeUnit
)
||
!
failsafeInvokePsetEx
(
connection
))
{
connection
.
setEx
(
rawKey
,
TimeoutUtils
.
toSeconds
(
time
,
timeUnit
),
rawValue
);
}
}
private
boolean
failsafeInvokePsetEx
(
RedisConnection
connection
)
{
boolean
failed
=
false
;
try
{
connection
.
pSetEx
(
rawKey
,
time
,
rawValue
);
}
catch
(
UnsupportedOperationException
e
)
{
failed
=
true
;
}
return
!
failed
;
}
},
true
);
}
/**
...
...
@@ -420,6 +449,13 @@ public class RedisRepository {
RedisSerializer
<
Object
>
redisSerializer
=
(
RedisSerializer
<
Object
>)
redisTemplate
.
getKeySerializer
();
return
redisSerializer
.
serialize
(
key
);
}
private
byte
[]
rawValue
(
Object
value
,
RedisSerializer
valueSerializer
)
{
if
(
value
instanceof
byte
[])
{
return
(
byte
[])
value
;
}
return
valueSerializer
.
serialize
(
value
);
}
private
List
deserializeValues
(
List
<
byte
[]>
rawValues
,
RedisSerializer
<
Object
>
valueSerializer
)
{
if
(
valueSerializer
==
null
)
{
...
...
zlt-doc/sql/user-center.sql
浏览文件 @
79ca39ff
...
...
@@ -123,7 +123,7 @@ INSERT INTO `sys_menu` VALUES (2, 12, '用户管理', '#!user', 'system/user.htm
INSERT
INTO
`sys_menu`
VALUES
(
3
,
12
,
'角色管理'
,
'#!role'
,
'system/role.html'
,
NULL
,
'layui-icon-user'
,
3
,
'2017-11-17 16:56:59'
,
'2019-01-14 15:34:40'
,
1
,
0
,
'webApp'
);
INSERT
INTO
`sys_menu`
VALUES
(
4
,
12
,
'菜单管理'
,
'#!menus'
,
'system/menus.html'
,
NULL
,
'layui-icon-menu-fill'
,
4
,
'2017-11-17 16:56:59'
,
'2018-09-03 02:23:47'
,
1
,
0
,
'webApp'
);
INSERT
INTO
`sys_menu`
VALUES
(
9
,
37
,
'文件中心'
,
'#!files'
,
'files/files.html'
,
NULL
,
'layui-icon-file'
,
3
,
'2017-11-17 16:56:59'
,
'2019-01-17 20:18:44'
,
1
,
0
,
'webApp'
);
INSERT
INTO
`sys_menu`
VALUES
(
10
,
37
,
'文档中心'
,
'#!swagger'
,
'http://127.0.0.1:9900/
swagger-ui
.html'
,
NULL
,
'layui-icon-app'
,
4
,
'2017-11-17 16:56:59'
,
'2019-01-17 20:18:48'
,
1
,
0
,
'webApp'
);
INSERT
INTO
`sys_menu`
VALUES
(
10
,
37
,
'文档中心'
,
'#!swagger'
,
'http://127.0.0.1:9900/
doc
.html'
,
NULL
,
'layui-icon-app'
,
4
,
'2017-11-17 16:56:59'
,
'2019-01-17 20:18:48'
,
1
,
0
,
'webApp'
);
INSERT
INTO
`sys_menu`
VALUES
(
11
,
12
,
'我的信息'
,
'#!myInfo'
,
'system/myInfo.html'
,
NULL
,
'layui-icon-login-qq'
,
10
,
'2017-11-17 16:56:59'
,
'2018-09-02 06:12:24'
,
1
,
0
,
'webApp'
);
INSERT
INTO
`sys_menu`
VALUES
(
12
,
-
1
,
'认证管理'
,
'javascript:;'
,
''
,
NULL
,
'layui-icon-set'
,
1
,
'2017-11-17 16:56:59'
,
'2018-12-13 15:02:49'
,
1
,
0
,
'webApp'
);
INSERT
INTO
`sys_menu`
VALUES
(
35
,
12
,
'应用管理'
,
'#!app'
,
'attestation/app.html'
,
NULL
,
'layui-icon-link'
,
5
,
'2017-11-17 16:56:59'
,
'2019-01-14 15:35:15'
,
1
,
0
,
'webApp'
);
...
...
zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisAuthorizationCodeServices.java
浏览文件 @
79ca39ff
package
com.central.oauth.service.impl
;
import
com.central.common.redis.template.RedisRepository
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
org.springframework.security.oauth2.provider.OAuth2Authentication
;
import
org.springframework.security.oauth2.provider.code.RandomValueAuthorizationCodeServices
;
import
org.springframework.stereotype.Service
;
...
...
@@ -8,15 +10,21 @@ import org.springframework.stereotype.Service;
import
java.util.concurrent.TimeUnit
;
/**
* @author zlt
* JdbcAuthorizationCodeServices替换
*
* @author zlt
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@Service
public
class
RedisAuthorizationCodeServices
extends
RandomValueAuthorizationCodeServices
{
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
private
final
RedisRepository
redisRepository
;
private
final
RedisSerializer
<
Object
>
valueSerializer
;
public
RedisAuthorizationCodeServices
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
this
.
redisTemplate
=
redisTemplate
;
public
RedisAuthorizationCodeServices
(
RedisRepository
redisRepository
)
{
this
.
redisRepository
=
redisRepository
;
this
.
valueSerializer
=
RedisSerializer
.
java
();
}
/**
...
...
@@ -25,14 +33,14 @@ public class RedisAuthorizationCodeServices extends RandomValueAuthorizationCode
*/
@Override
protected
void
store
(
String
code
,
OAuth2Authentication
authentication
)
{
redis
Template
.
opsForValue
().
set
(
redisKey
(
code
),
authentication
,
10
,
TimeUnit
.
MINUTES
);
redis
Repository
.
setExpire
(
redisKey
(
code
),
authentication
,
10
,
TimeUnit
.
MINUTES
,
valueSerializer
);
}
@Override
protected
OAuth2Authentication
remove
(
final
String
code
)
{
String
codeKey
=
redisKey
(
code
);
OAuth2Authentication
token
=
(
OAuth2Authentication
)
redis
Template
.
opsForValue
().
get
(
codeKey
);
this
.
redisTemplate
.
delete
(
codeKey
);
OAuth2Authentication
token
=
(
OAuth2Authentication
)
redis
Repository
.
get
(
codeKey
,
valueSerializer
);
redisRepository
.
del
(
codeKey
);
return
token
;
}
...
...
zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisTokensServiceImpl.java
浏览文件 @
79ca39ff
...
...
@@ -25,6 +25,9 @@ import java.util.Map;
*
* @author zlt
* @date 2019/7/12
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@Slf4j
@Service
...
...
@@ -43,7 +46,6 @@ public class RedisTokensServiceImpl implements ITokensService {
List
<
TokenVo
>
result
=
new
ArrayList
<>(
limit
);
RedisSerializer
<
Object
>
valueSerializer
=
RedisSerializer
.
java
();
//查询token集合
//redisRepository.getRedisTemplate().e
List
<
Object
>
tokenObjs
=
redisRepository
.
getList
(
redisKey
,
startEnds
[
0
],
startEnds
[
1
]-
1
,
valueSerializer
);
if
(
tokenObjs
!=
null
)
{
for
(
Object
obj
:
tokenObjs
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录