Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
程序猿小郑
microservices-platform
提交
8c34b8e8
microservices-platform
项目概览
程序猿小郑
/
microservices-platform
与 Fork 源项目一致
Fork自
zlt2000 / microservices-platform
通知
4
Star
1
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 搜索 >>
提交
8c34b8e8
编写于
9月 30, 2020
作者:
zlt2000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #I1X2U5 redis的increment命令的反序列化问题
上级
aff3044a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
69 addition
and
7 deletion
+69
-7
zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthRedisTokenStore.java
.../com/central/oauth2/common/store/AuthRedisTokenStore.java
+2
-2
zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/CustomRedisTokenStore.java
...om/central/oauth2/common/store/CustomRedisTokenStore.java
+9
-2
zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java
...ain/java/com/central/common/redis/RedisAutoConfigure.java
+1
-1
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
+52
-0
zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisTokensServiceImpl.java
...om/central/oauth/service/impl/RedisTokensServiceImpl.java
+5
-2
未找到文件。
zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthRedisTokenStore.java
浏览文件 @
8c34b8e8
...
...
@@ -21,7 +21,7 @@ import org.springframework.security.oauth2.provider.token.TokenStore;
@ConditionalOnProperty
(
prefix
=
"zlt.oauth2.token.store"
,
name
=
"type"
,
havingValue
=
"redis"
,
matchIfMissing
=
true
)
public
class
AuthRedisTokenStore
{
@Bean
public
TokenStore
tokenStore
(
RedisConnectionFactory
connectionFactory
,
SecurityProperties
securityProperties
)
{
return
new
CustomRedisTokenStore
(
connectionFactory
,
securityProperties
);
public
TokenStore
tokenStore
(
RedisConnectionFactory
connectionFactory
,
SecurityProperties
securityProperties
,
RedisSerializer
<
Object
>
redisValueSerializer
)
{
return
new
CustomRedisTokenStore
(
connectionFactory
,
securityProperties
,
redisValueSerializer
);
}
}
zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/CustomRedisTokenStore.java
浏览文件 @
8c34b8e8
...
...
@@ -4,6 +4,7 @@ import com.central.common.constant.SecurityConstants;
import
com.central.oauth2.common.properties.SecurityProperties
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
org.springframework.security.oauth2.common.DefaultOAuth2AccessToken
;
import
org.springframework.security.oauth2.common.ExpiringOAuth2RefreshToken
;
import
org.springframework.security.oauth2.common.OAuth2AccessToken
;
...
...
@@ -61,9 +62,15 @@ public class CustomRedisTokenStore implements TokenStore {
*/
private
SecurityProperties
securityProperties
;
public
CustomRedisTokenStore
(
RedisConnectionFactory
connectionFactory
,
SecurityProperties
securityProperties
)
{
/**
* 业务redis的value序列化
*/
private
RedisSerializer
<
Object
>
redisValueSerializer
;
public
CustomRedisTokenStore
(
RedisConnectionFactory
connectionFactory
,
SecurityProperties
securityProperties
,
RedisSerializer
<
Object
>
redisValueSerializer
)
{
this
.
connectionFactory
=
connectionFactory
;
this
.
securityProperties
=
securityProperties
;
this
.
redisValueSerializer
=
redisValueSerializer
;
if
(
springDataRedis_2_0
)
{
this
.
loadRedisConnectionMethods_2_0
();
}
...
...
@@ -111,7 +118,7 @@ public class CustomRedisTokenStore implements TokenStore {
}
private
ClientDetails
deserializeClientDetails
(
byte
[]
bytes
)
{
return
serializationStrategy
.
deserialize
(
bytes
,
ClientDetails
.
clas
s
);
return
(
ClientDetails
)
redisValueSerializer
.
deserialize
(
byte
s
);
}
private
byte
[]
serialize
(
String
string
)
{
...
...
zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java
浏览文件 @
8c34b8e8
...
...
@@ -41,7 +41,7 @@ public class RedisAutoConfigure {
@Bean
public
RedisSerializer
<
Object
>
redisValueSerializer
()
{
return
RedisSerializer
.
j
ava
();
return
RedisSerializer
.
j
son
();
}
/**
...
...
zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java
浏览文件 @
8c34b8e8
...
...
@@ -8,6 +8,9 @@ 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.serializer.RedisSerializer
;
import
org.springframework.data.redis.serializer.SerializationUtils
;
import
org.springframework.util.Assert
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -146,6 +149,17 @@ public class RedisRepository {
public
Object
get
(
final
String
key
)
{
return
redisTemplate
.
opsForValue
().
get
(
key
);
}
/**
* 根据key获取对象
*
* @param key the key
* @param valueSerializer 序列化
* @return the string
*/
public
Object
get
(
final
String
key
,
RedisSerializer
<
Object
>
valueSerializer
)
{
byte
[]
rawKey
=
rawKey
(
key
);
return
redisTemplate
.
execute
(
connection
->
deserializeValue
(
connection
.
get
(
rawKey
),
valueSerializer
),
true
);
}
/**
* Ops for hash hash operations.
...
...
@@ -361,6 +375,20 @@ public class RedisRepository {
return
opsForList
().
range
(
key
,
start
,
end
);
}
/**
* redis List数据结构 : 返回列表 key 中指定区间内的元素,区间以偏移量 start 和 end 指定。
*
* @param key the key
* @param start the start
* @param end the end
* @param valueSerializer 序列化
* @return the list
*/
public
List
<
Object
>
getList
(
String
key
,
int
start
,
int
end
,
RedisSerializer
<
Object
>
valueSerializer
)
{
byte
[]
rawKey
=
rawKey
(
key
);
return
redisTemplate
.
execute
(
connection
->
deserializeValues
(
connection
.
lRange
(
rawKey
,
start
,
end
),
valueSerializer
),
true
);
}
/**
* redis List数据结构 : 批量存储
*
...
...
@@ -382,4 +410,28 @@ public class RedisRepository {
public
void
insert
(
String
key
,
long
index
,
Object
value
)
{
opsForList
().
set
(
key
,
index
,
value
);
}
private
byte
[]
rawKey
(
Object
key
)
{
Assert
.
notNull
(
key
,
"non null key required"
);
if
(
key
instanceof
byte
[])
{
return
(
byte
[])
key
;
}
RedisSerializer
<
Object
>
redisSerializer
=
(
RedisSerializer
<
Object
>)
redisTemplate
.
getKeySerializer
();
return
redisSerializer
.
serialize
(
key
);
}
private
List
deserializeValues
(
List
<
byte
[]>
rawValues
,
RedisSerializer
<
Object
>
valueSerializer
)
{
if
(
valueSerializer
==
null
)
{
return
rawValues
;
}
return
SerializationUtils
.
deserialize
(
rawValues
,
valueSerializer
);
}
private
Object
deserializeValue
(
byte
[]
value
,
RedisSerializer
<
Object
>
valueSerializer
)
{
if
(
valueSerializer
==
null
)
{
return
value
;
}
return
valueSerializer
.
deserialize
(
value
);
}
}
zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisTokensServiceImpl.java
浏览文件 @
8c34b8e8
...
...
@@ -10,6 +10,7 @@ import com.central.oauth.service.ITokensService;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.MapUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
org.springframework.security.oauth2.common.DefaultOAuth2AccessToken
;
import
org.springframework.security.oauth2.provider.OAuth2Authentication
;
import
org.springframework.security.oauth2.provider.OAuth2Request
;
...
...
@@ -40,8 +41,10 @@ public class RedisTokensServiceImpl implements ITokensService {
String
redisKey
=
getRedisKey
(
params
,
clientId
);
long
size
=
redisRepository
.
length
(
redisKey
);
List
<
TokenVo
>
result
=
new
ArrayList
<>(
limit
);
RedisSerializer
<
Object
>
valueSerializer
=
RedisSerializer
.
java
();
//查询token集合
List
<
Object
>
tokenObjs
=
redisRepository
.
getList
(
redisKey
,
startEnds
[
0
],
startEnds
[
1
]-
1
);
//redisRepository.getRedisTemplate().e
List
<
Object
>
tokenObjs
=
redisRepository
.
getList
(
redisKey
,
startEnds
[
0
],
startEnds
[
1
]-
1
,
valueSerializer
);
if
(
tokenObjs
!=
null
)
{
for
(
Object
obj
:
tokenObjs
)
{
DefaultOAuth2AccessToken
accessToken
=
(
DefaultOAuth2AccessToken
)
obj
;
...
...
@@ -51,7 +54,7 @@ public class RedisTokensServiceImpl implements ITokensService {
tokenVo
.
setExpiration
(
accessToken
.
getExpiration
());
//获取用户信息
Object
authObj
=
redisRepository
.
get
(
SecurityConstants
.
REDIS_TOKEN_AUTH
+
accessToken
.
getValue
());
Object
authObj
=
redisRepository
.
get
(
SecurityConstants
.
REDIS_TOKEN_AUTH
+
accessToken
.
getValue
()
,
valueSerializer
);
OAuth2Authentication
authentication
=
(
OAuth2Authentication
)
authObj
;
if
(
authentication
!=
null
)
{
OAuth2Request
request
=
authentication
.
getOAuth2Request
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录