@@ -2,7 +2,6 @@ package com.aida.lanecarford.common.security;
import com.aida.lanecarford.common.security.config.JwtProperties ;
import com.aida.lanecarford.common.security.config.JwtProperties ;
import com.aida.lanecarford.common.security.context.UserContext ;
import com.aida.lanecarford.common.security.context.UserContext ;
import com.aida.lanecarford.exception.BusinessException ;
import com.aida.lanecarford.util.CacheUtil ;
import com.aida.lanecarford.util.CacheUtil ;
import com.aida.lanecarford.vo.AuthPrincipalVO ;
import com.aida.lanecarford.vo.AuthPrincipalVO ;
import com.alibaba.fastjson.JSONObject ;
import com.alibaba.fastjson.JSONObject ;
@@ -25,7 +24,7 @@ public class JwtInterceptor implements HandlerInterceptor {
private final JwtProperties jwtProperties ;
private final JwtProperties jwtProperties ;
@Override
@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 ( ) ) ) {
if ( " OPTIONS " . equalsIgnoreCase ( request . getMethod ( ) ) ) {
return true ;
return true ;
}
}
@@ -41,7 +40,8 @@ public class JwtInterceptor implements HandlerInterceptor {
String extracted = jwtUtil . extractUserinfo ( jwtToken ) ;
String extracted = jwtUtil . extractUserinfo ( jwtToken ) ;
if ( StringUtil . isNullOrEmpty ( extracted ) ) {
if ( StringUtil . isNullOrEmpty ( extracted ) ) {
log . warn ( " TOKEN已过期, 请重新登录! (token without userInfo) " ) ;
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 ) ;
AuthPrincipalVO authPrincipalVO = JSONObject . parseObject ( extracted , AuthPrincipalVO . class ) ;
@@ -54,10 +54,12 @@ public class JwtInterceptor implements HandlerInterceptor {
if ( Objects . isNull ( token ) ) {
if ( Objects . isNull ( token ) ) {
log . warn ( " TOKEN已过期, 请重新登录! (local cache empty) " ) ;
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 ) ) {
} else if ( ! token . toString ( ) . equals ( jwtToken ) ) {
log . warn ( " TOKEN已过期, 请重新登录! (token not match local cache) " ) ;
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 ;
return true ;
}
}