|  | @@ -4,6 +4,7 @@ import cn.hnthyy.thmz.Utils.TokenUtil;
 | 
	
		
			
				|  |  |  import cn.hnthyy.thmz.comment.PassToken;
 | 
	
		
			
				|  |  |  import cn.hnthyy.thmz.comment.UserLoginToken;
 | 
	
		
			
				|  |  |  import cn.hnthyy.thmz.common.Constants;
 | 
	
		
			
				|  |  | +import cn.hnthyy.thmz.entity.AuthException;
 | 
	
		
			
				|  |  |  import cn.hnthyy.thmz.entity.thmz.Token;
 | 
	
		
			
				|  |  |  import cn.hnthyy.thmz.service.thmz.TokenService;
 | 
	
		
			
				|  |  |  import com.auth0.jwt.JWT;
 | 
	
	
		
			
				|  | @@ -27,7 +28,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
 | 
	
		
			
				|  |  |      private TokenService tokenService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object) {
 | 
	
		
			
				|  |  | +    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object) throws AuthException {
 | 
	
		
			
				|  |  |          // 从 http 请求头中取出 token
 | 
	
		
			
				|  |  |          String token = TokenUtil.getToken(httpServletRequest);
 | 
	
		
			
				|  |  |          // 如果不是映射到方法直接通过
 | 
	
	
		
			
				|  | @@ -47,12 +48,12 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
 | 
	
		
			
				|  |  |          if (method.isAnnotationPresent(UserLoginToken.class)) {
 | 
	
		
			
				|  |  |              // 执行认证
 | 
	
		
			
				|  |  |              if (token == null) {
 | 
	
		
			
				|  |  | -                throw new RuntimeException("401");
 | 
	
		
			
				|  |  | +                throw new AuthException("401");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              Token tokenObject = tokenService.queryFromCache(token);
 | 
	
		
			
				|  |  |              if (tokenObject != null) {
 | 
	
		
			
				|  |  |                  //token已经失效,实际是退出登录主动失效了token
 | 
	
		
			
				|  |  | -                throw new RuntimeException("401");
 | 
	
		
			
				|  |  | +                throw new AuthException("401");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              // 验证 token
 | 
	
		
			
				|  |  |              JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(Constants.JWT_SECRET)).build();
 | 
	
	
		
			
				|  | @@ -60,7 +61,7 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
 | 
	
		
			
				|  |  |                  jwtVerifier.verify(token);
 | 
	
		
			
				|  |  |              } catch (JWTVerificationException e) {
 | 
	
		
			
				|  |  |                  //token超时
 | 
	
		
			
				|  |  | -                throw new RuntimeException("401");
 | 
	
		
			
				|  |  | +                throw new AuthException("401");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return true;
 | 
	
		
			
				|  |  |          }
 |