he2802 2 anni fa
parent
commit
cbbf3fcf47

+ 7 - 0
zhongzheng-api/src/main/java/com/zhongzheng/controller/cmmon/CommonController.java

@@ -7,6 +7,7 @@ import com.zhongzheng.common.core.controller.BaseController;
 import com.zhongzheng.common.core.domain.AjaxResult;
 import com.zhongzheng.common.core.page.TableDataInfo;
 import com.zhongzheng.common.core.redis.RedisCache;
+import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.common.utils.DateUtils;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.common.utils.ToolsUtils;
@@ -47,6 +48,7 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -368,4 +370,9 @@ public class CommonController extends BaseController {
         List<ActivityGoodsPriceVo> list = iDistributionActivityGoodsService.getGoodsList(bo);
         return getDataTable(list);
     }
+
+    @RequestMapping("/token_offline")
+    public void loginAuthFailOffLine() {
+        throw new CustomException("用户验证错误",409);
+    }
 }

+ 5 - 0
zhongzheng-framework/src/main/java/com/zhongzheng/framework/security/filter/JwtAuthenticationTokenFilter.java

@@ -4,6 +4,7 @@ import cn.hutool.core.lang.Validator;
 import cn.hutool.http.HttpStatus;
 import com.zhongzheng.common.core.domain.AjaxResult;
 import com.zhongzheng.common.core.domain.model.TopLoginUser;
+import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.framework.web.service.TopTokenService;
 import com.zhongzheng.modules.user.entity.ClientLoginSeller;
 import com.zhongzheng.modules.user.entity.ClientLoginUser;
@@ -53,12 +54,16 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
         try{
             String wxToken = wxTokenService.getToken(request);
             if(StringUtils.isNoneEmpty(wxToken)){
+                wxTokenService.setResponse(response);
                 ClientLoginUser clientLoginUser = wxTokenService.getLoginUser(request);
                 if(clientLoginUser!=null){
                     wxTokenService.verifyToken(clientLoginUser);
                     UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(clientLoginUser, null,null);
                     authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
                     SecurityContextHolder.getContext().setAuthentication(authenticationToken);
+                }else{
+                    request.getRequestDispatcher("/app/common/token_offline").forward(request, response);
+                    return;
                 }
             }else{
                 if(!enabledTenant){

+ 6 - 3
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/WxTokenService.java

@@ -26,6 +26,7 @@ import io.jsonwebtoken.Jwts;
 import io.jsonwebtoken.SignatureAlgorithm;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.security.access.AccessDeniedException;
 import org.springframework.security.authentication.AuthenticationManager;
 import org.springframework.security.authentication.BadCredentialsException;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -33,7 +34,10 @@ import org.springframework.security.core.Authentication;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
@@ -81,8 +85,7 @@ public class WxTokenService
      *
      * @return 用户信息
      */
-    public ClientLoginUser getLoginUser(HttpServletRequest request)
-    {
+    public ClientLoginUser getLoginUser(HttpServletRequest request) {
         //测试用户
         String test_token = request.getHeader("X-Auth-Token");
         if("test".equals(test_token)){
@@ -96,7 +99,7 @@ public class WxTokenService
             // 解析对应的权限以及用户信息
             String uuid = (String) claims.get(Constants.WX_LOGIN_USER_KEY);
             if(!iUserLoginKeyService.queryByUserKey(uuid)){
-                throw new BaseException(null,"409",null,"已被踢下线");
+                return null;
             }
             String userKey = getTokenKey(uuid);
             ClientLoginUser user = redisCache.getCacheObject(userKey);

+ 2 - 0
zhongzheng-generator/src/main/java/com/zhongzheng/generator/controller/FilterController.java

@@ -15,4 +15,6 @@ public class FilterController {
     public void loginAuthFail(HttpServletRequest request) {
         throw new AccessDeniedException("用户验证错误");
     }
+
+
 }