diff --git a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/security/JeecgRedisOAuth2AuthorizationService.java b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/security/JeecgRedisOAuth2AuthorizationService.java index d46ab3ce..960a20e1 100644 --- a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/security/JeecgRedisOAuth2AuthorizationService.java +++ b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/security/JeecgRedisOAuth2AuthorizationService.java @@ -43,9 +43,11 @@ public class JeecgRedisOAuth2AuthorizationService implements OAuth2Authorization if (isState(authorization)) { String token = authorization.getAttribute("state"); + RedisSerializer redisSerializer = redisTemplate.getValueSerializer(); redisTemplate.setValueSerializer(RedisSerializer.java()); redisTemplate.opsForValue().set(buildKey(OAuth2ParameterNames.STATE, token), authorization, TIMEOUT, TimeUnit.MINUTES); + redisTemplate.setValueSerializer(redisSerializer); } if (isCode(authorization)) { @@ -54,22 +56,27 @@ public class JeecgRedisOAuth2AuthorizationService implements OAuth2Authorization OAuth2AuthorizationCode authorizationCodeToken = authorizationCode.getToken(); long between = ChronoUnit.MINUTES.between(authorizationCodeToken.getIssuedAt(), authorizationCodeToken.getExpiresAt()); + RedisSerializer redisSerializer = redisTemplate.getValueSerializer(); redisTemplate.setValueSerializer(RedisSerializer.java()); redisTemplate.opsForValue().set(buildKey(OAuth2ParameterNames.CODE, authorizationCodeToken.getTokenValue()), authorization, between, TimeUnit.MINUTES); + redisTemplate.setValueSerializer(redisSerializer); } if (isRefreshToken(authorization)) { OAuth2RefreshToken refreshToken = authorization.getRefreshToken().getToken(); long between = ChronoUnit.SECONDS.between(refreshToken.getIssuedAt(), refreshToken.getExpiresAt()); + RedisSerializer redisSerializer = redisTemplate.getValueSerializer(); redisTemplate.setValueSerializer(RedisSerializer.java()); redisTemplate.opsForValue().set(buildKey(OAuth2ParameterNames.REFRESH_TOKEN, refreshToken.getTokenValue()), authorization, between, TimeUnit.SECONDS); + redisTemplate.setValueSerializer(redisSerializer); } if (isAccessToken(authorization)) { OAuth2AccessToken accessToken = authorization.getAccessToken().getToken(); long between = ChronoUnit.SECONDS.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()); + RedisSerializer redisSerializer = redisTemplate.getValueSerializer(); redisTemplate.setValueSerializer(RedisSerializer.java()); redisTemplate.opsForValue().set(buildKey(OAuth2ParameterNames.ACCESS_TOKEN, accessToken.getTokenValue()), authorization, between, TimeUnit.SECONDS); @@ -77,6 +84,7 @@ public class JeecgRedisOAuth2AuthorizationService implements OAuth2Authorization // 扩展记录 access-token 、username 的关系 1::token::username::admin::xxx String tokenUsername = String.format("%s::%s::%s", AUTHORIZATION, authorization.getPrincipalName(), accessToken.getTokenValue()); redisTemplate.opsForValue().set(tokenUsername, accessToken.getTokenValue(), between, TimeUnit.SECONDS); + redisTemplate.setValueSerializer(redisSerializer); } } @@ -125,8 +133,11 @@ public class JeecgRedisOAuth2AuthorizationService implements OAuth2Authorization public OAuth2Authorization findByToken(String token, @Nullable OAuth2TokenType tokenType) { Assert.hasText(token, "token cannot be empty"); Assert.notNull(tokenType, "tokenType cannot be empty"); + RedisSerializer redisSerializer = redisTemplate.getValueSerializer(); redisTemplate.setValueSerializer(RedisSerializer.java()); - return (OAuth2Authorization) redisTemplate.opsForValue().get(buildKey(tokenType.getValue(), token)); + OAuth2Authorization oAuth2Authorization = (OAuth2Authorization) redisTemplate.opsForValue().get(buildKey(tokenType.getValue(), token)); + redisTemplate.setValueSerializer(redisSerializer); + return oAuth2Authorization; } private String buildKey(String type, String id) {