修复redis序列化问题
This commit is contained in:
+15
-7
@@ -1,6 +1,8 @@
|
||||
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) {
|
||||
redisTemplate.opsForValue().set(redisKey(code), authentication, 10, TimeUnit.MINUTES);
|
||||
redisRepository.setExpire(redisKey(code), authentication, 10, TimeUnit.MINUTES, valueSerializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OAuth2Authentication remove(final String code) {
|
||||
String codeKey = redisKey(code);
|
||||
OAuth2Authentication token = (OAuth2Authentication) redisTemplate.opsForValue().get(codeKey);
|
||||
this.redisTemplate.delete(codeKey);
|
||||
OAuth2Authentication token = (OAuth2Authentication) redisRepository.get(codeKey, valueSerializer);
|
||||
redisRepository.del(codeKey);
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user