|
@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.security.MessageDigest;
|
|
import java.security.MessageDigest;
|
|
|
import java.util.Base64;
|
|
import java.util.Base64;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
@@ -265,6 +266,8 @@ public class JwtInterceptor implements HandlerInterceptor {
|
|
|
String key = TOKEN_PREFIX.replace("{token}", token);
|
|
String key = TOKEN_PREFIX.replace("{token}", token);
|
|
|
String loginUserString = redisUtils.getString(key);
|
|
String loginUserString = redisUtils.getString(key);
|
|
|
if (StringUtils.isBlank(loginUserString)) {
|
|
if (StringUtils.isBlank(loginUserString)) {
|
|
|
|
|
+ // token 已过期,从列表中清理
|
|
|
|
|
+ cleanExpiredToken(token);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
ContentPlatformAccount account = JSON.parseObject(loginUserString, ContentPlatformAccount.class);
|
|
ContentPlatformAccount account = JSON.parseObject(loginUserString, ContentPlatformAccount.class);
|
|
@@ -285,6 +288,40 @@ public class JwtInterceptor implements HandlerInterceptor {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 触发清理:遍历该手机号的所有 token,移除已过期的
|
|
|
|
|
+ */
|
|
|
|
|
+ private void cleanExpiredToken(String token) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String telKey = "login.token.tel." + token;
|
|
|
|
|
+ String telNum = redisUtils.getString(telKey);
|
|
|
|
|
+ if (StringUtils.isBlank(telNum)) {
|
|
|
|
|
+ redisUtils.del(telKey);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String listKey = "login.account.token.list." + telNum;
|
|
|
|
|
+ List<String> tokens = redisUtils.listRange(listKey);
|
|
|
|
|
+ if (tokens == null || tokens.isEmpty()) {
|
|
|
|
|
+ redisUtils.del(telKey);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (String t : tokens) {
|
|
|
|
|
+ if (StringUtils.isBlank(t)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String loginKey = TOKEN_PREFIX.replace("{token}", t);
|
|
|
|
|
+ if (StringUtils.isBlank(redisUtils.getString(loginKey))) {
|
|
|
|
|
+ // token 已过期,从列表和映射中移除
|
|
|
|
|
+ redisUtils.listRemove(listKey, t);
|
|
|
|
|
+ redisUtils.del("login.token.tel." + t);
|
|
|
|
|
+ redisUtils.del("sign_key." + t);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("cleanExpiredToken error, token={}", token, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception
|
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception
|
|
|
ex) throws Exception {
|
|
ex) throws Exception {
|