|
@@ -1,13 +1,12 @@
|
|
|
package com.chelvc.framework.security.token;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
import com.chelvc.framework.base.context.ApplicationContextHolder;
|
|
|
import com.chelvc.framework.base.context.SessionContextHolder;
|
|
|
import com.chelvc.framework.base.context.Using;
|
|
|
import com.chelvc.framework.common.util.DateUtils;
|
|
|
-import com.chelvc.framework.common.util.ObjectUtils;
|
|
|
import com.chelvc.framework.common.util.StringUtils;
|
|
|
import com.chelvc.framework.redis.context.RedisContextHolder;
|
|
|
import com.chelvc.framework.redis.context.RedisHashHolder;
|
|
@@ -42,18 +41,12 @@ public class RedisSessionValidator extends DefaultSessionValidator {
|
|
|
return OAuth2TokenValidatorResult.success();
|
|
|
}
|
|
|
|
|
|
- // 从Redis获取令牌信息
|
|
|
+ // 校验令牌有效性
|
|
|
Long id = this.getId(jwt);
|
|
|
- String terminal = String.valueOf(SessionContextHolder.getTerminal());
|
|
|
RedisTemplate<String, Object> template = RedisContextHolder.getDefaultTemplate();
|
|
|
- List<?> values = RedisHashHolder.get(
|
|
|
- template, AuthorizeContextHolder.key(id),
|
|
|
- terminal, AuthorizeContextHolder.SCOPE, AuthorizeContextHolder.MOBILE,
|
|
|
- AuthorizeContextHolder.REGISTERING
|
|
|
- );
|
|
|
-
|
|
|
- // 校验令牌有效性及应用范围
|
|
|
- String token = ObjectUtils.get(values, 0), scope = this.getScope(jwt);
|
|
|
+ Map<String, ?> context = RedisHashHolder.get(template, AuthorizeContextHolder.key(id));
|
|
|
+ String terminal = String.valueOf(SessionContextHolder.getTerminal());
|
|
|
+ String token = (String) context.get(terminal), scope = this.getScope(jwt);
|
|
|
if (StringUtils.isEmpty(token)) {
|
|
|
throw new OAuth2AuthenticationException(new OAuth2Error(
|
|
|
"TOKEN_EXPIRED", ApplicationContextHolder.getMessage("Token.Expired"), null
|
|
@@ -65,7 +58,7 @@ public class RedisSessionValidator extends DefaultSessionValidator {
|
|
|
));
|
|
|
} else if (this.properties.getAuthorize().isScoped()) {
|
|
|
// 判断应用范围是否相同,如果不同则表示应用范围已被重置,需要刷新令牌
|
|
|
- String real = ObjectUtils.get(values, 1);
|
|
|
+ String real = (String) context.get(AuthorizeContextHolder.SCOPE);
|
|
|
if (!Objects.equals(scope, real)) {
|
|
|
String arg = StringUtils.ifEmpty(real, ApplicationContextHolder::getMessage);
|
|
|
String message = ApplicationContextHolder.getMessage("Scope.Changed", new Object[]{arg});
|
|
@@ -74,8 +67,8 @@ public class RedisSessionValidator extends DefaultSessionValidator {
|
|
|
}
|
|
|
|
|
|
// 更新会话主体信息
|
|
|
- String mobile = ObjectUtils.get(values, 2);
|
|
|
- Long registering = ObjectUtils.get(values, 3);
|
|
|
+ String mobile = (String) context.get(AuthorizeContextHolder.MOBILE);
|
|
|
+ Long registering = (Long) context.get(AuthorizeContextHolder.REGISTERING);
|
|
|
long usage = RedisUserDailyHashHolder.increment(template, id, "usage");
|
|
|
Using using = usage > 1 || registering == null ? Using.NORMAL :
|
|
|
registering >= DateUtils.today().getTime() ? Using.NEWLY : Using.DAILY;
|