BUGFIX:token过期都返回401

This commit is contained in:
2025-12-23 14:30:24 +08:00
parent 2972ab1dca
commit 91eb21aa84
2 changed files with 9 additions and 5 deletions

View File

@@ -2,7 +2,6 @@ package com.aida.lanecarford.common.security;
import com.aida.lanecarford.common.security.config.JwtProperties;
import com.aida.lanecarford.common.security.context.UserContext;
import com.aida.lanecarford.exception.BusinessException;
import com.aida.lanecarford.util.CacheUtil;
import com.aida.lanecarford.vo.AuthPrincipalVO;
import com.alibaba.fastjson.JSONObject;
@@ -25,7 +24,7 @@ public class JwtInterceptor implements HandlerInterceptor {
private final JwtProperties jwtProperties;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
return true;
}
@@ -41,7 +40,8 @@ public class JwtInterceptor implements HandlerInterceptor {
String extracted = jwtUtil.extractUserinfo(jwtToken);
if (StringUtil.isNullOrEmpty(extracted)) {
log.warn("TOKEN已过期请重新登录(token without userInfo)");
throw new BusinessException("Token has expired, please log in again.");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
// throw new BusinessException("Token has expired, please log in again.");
}
AuthPrincipalVO authPrincipalVO = JSONObject.parseObject(extracted, AuthPrincipalVO.class);
@@ -54,10 +54,12 @@ public class JwtInterceptor implements HandlerInterceptor {
if (Objects.isNull(token)) {
log.warn("TOKEN已过期请重新登录(local cache empty)");
throw new BusinessException("Token has expired, please log in again.");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
// throw new BusinessException("Token has expired, please log in again.");
} else if (!token.toString().equals(jwtToken)) {
log.warn("TOKEN已过期请重新登录(token not match local cache)");
throw new BusinessException("Token has expired, please log in again.");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
// throw new BusinessException("Token has expired, please log in again.");
}
return true;
}

View File

@@ -108,6 +108,8 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
customer.setCreatedTime(LocalDateTime.now());
save(customer);
} else {
throw new BusinessException("VIP ID'" + vipId + "' already exists.Please proceed directly to check-in.");
}
return customer;