|
@@ -15,6 +15,7 @@ import com.chelvc.framework.redis.context.RedisContextHolder;
|
|
|
import com.chelvc.framework.redis.context.RedisHashHolder;
|
|
|
import com.chelvc.framework.redis.context.RedisUserDailyHashHolder;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
@@ -31,11 +32,12 @@ import org.springframework.stereotype.Component;
|
|
|
* @author Woody
|
|
|
* @date 2024/1/30
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Component
|
|
|
@ConditionalOnClass(RedisContextHolder.class)
|
|
|
@ConditionalOnProperty(value = "oauth.redis.enabled", havingValue = "true", matchIfMissing = true)
|
|
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
-public class RedisSessionValidator implements SessionValidator {
|
|
|
+public class RedisSessionValidator extends DefaultSessionValidator {
|
|
|
private final OAuthProperties properties;
|
|
|
|
|
|
@Override
|
|
@@ -45,7 +47,7 @@ public class RedisSessionValidator implements SessionValidator {
|
|
|
}
|
|
|
|
|
|
// 从Redis获取令牌信息
|
|
|
- Long id = OAuthContextHolder.getId(jwt);
|
|
|
+ Long id = this.getId(jwt);
|
|
|
String terminal = String.valueOf(SessionContextHolder.getTerminal());
|
|
|
RedisTemplate<String, Object> template = RedisContextHolder.getDefaultTemplate();
|
|
|
List<?> values = RedisHashHolder.get(
|
|
@@ -54,8 +56,11 @@ public class RedisSessionValidator implements SessionValidator {
|
|
|
);
|
|
|
|
|
|
// 校验令牌有效性及应用范围
|
|
|
- String token = ObjectUtils.get(values, 0);
|
|
|
- String scope = OAuthContextHolder.getScope(jwt);
|
|
|
+ String token = ObjectUtils.get(values, 0), scope = this.getScope(jwt);
|
|
|
+ if (StringUtils.isEmpty(token)) {
|
|
|
+ // 兼容框架1.0版本
|
|
|
+ token = (String) template.opsForValue().get("token:" + terminal + ":" + id);
|
|
|
+ }
|
|
|
if (StringUtils.isEmpty(token)) {
|
|
|
throw new OAuth2AuthenticationException(new OAuth2Error(
|
|
|
"TOKEN_EXPIRED", ApplicationContextHolder.getMessage("Token.Expired"), null
|