|
@@ -3,10 +3,9 @@ package com.imed.costaccount.common.shiro;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.auth0.jwt.exceptions.TokenExpiredException;
|
|
|
-import com.imed.costaccount.common.token.ThreadLocalToken;
|
|
|
-import com.imed.costaccount.common.util.ErrorResult;
|
|
|
-import com.imed.costaccount.common.token.RedisUtil;
|
|
|
import com.imed.costaccount.common.token.JwtUtil;
|
|
|
+import com.imed.costaccount.common.token.RedisUtil;
|
|
|
+import com.imed.costaccount.common.util.ErrorResult;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.shiro.authc.AuthenticationException;
|
|
|
import org.apache.shiro.authc.AuthenticationToken;
|
|
@@ -98,6 +97,21 @@ public class OAuth2Filter extends AuthenticatingFilter {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ // 查看redis中token是否不存在了
|
|
|
+ int userId = jwtUtil.getUserId(token);
|
|
|
+ String redisToken = (String) redisUtil.get(userId + "");
|
|
|
+ if (StrUtil.isBlank(redisToken)) {
|
|
|
+ String json = JSONUtil.toJsonStr(ErrorResult.errorMsg(499, "令牌失效"));
|
|
|
+ resp.getWriter().print(json);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 如果两个缓存不一致,说明有人重新登录了
|
|
|
+ if (!token.equalsIgnoreCase(redisToken)) {
|
|
|
+ String json = JSONUtil.toJsonStr(ErrorResult.errorMsg(499, "您的账户在其他地方登录,请重新登录或修改密码!"));
|
|
|
+ resp.getWriter().print(json);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
// 内容是否过期
|
|
|
try {
|
|
|
jwtUtil.verifierToken(token);
|