From 0ba52b85b2d139dfb1f9b0e5d20b065bf8ee047d Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 21 Jan 2026 13:36:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=9F=A5=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/czg/config/SaTokenConfigure.java | 34 +++++++++++-------- .../src/main/java/com/czg/sa/MyStpLogic.java | 4 +-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/cash-common/cash-common-sa-token/src/main/java/com/czg/config/SaTokenConfigure.java b/cash-common/cash-common-sa-token/src/main/java/com/czg/config/SaTokenConfigure.java index 0db1729e8..df1ac3e23 100644 --- a/cash-common/cash-common-sa-token/src/main/java/com/czg/config/SaTokenConfigure.java +++ b/cash-common/cash-common-sa-token/src/main/java/com/czg/config/SaTokenConfigure.java @@ -43,7 +43,7 @@ public class SaTokenConfigure implements WebMvcConfigurer { userConfig.setIsShare(true); // config2.setTimeout(2000); userConfig.setTokenStyle("simple-uuid"); - MyStpLogic.CLIENT_LOGIC.setConfig(userConfig); + MyStpLogic.USER_LOGIC.setConfig(userConfig); } @PostConstruct @@ -62,21 +62,25 @@ public class SaTokenConfigure implements WebMvcConfigurer { // 重置根路径,防止satoken切割根路径导致匹配不到路径 ApplicationInfo.routePrefix = ""; - SaRouter.match("/user/**").notMatch("/user/login", "/user/test", "/user/geo/**", "/user/home/**", "/user/home/**", "/user/dict/**", "/user/openId") - .notMatch("/pay/**") - .notMatch("/notify/**") - .check(r -> MyStpLogic.CLIENT_LOGIC.checkLogin()) - .setHit(true) -// .match("/**") - .notMatch("/user/**") - .notMatch("/pay/**") - .notMatch("/notify/**") - .notMatch("/admin/auth/**") - .notMatch("/admin/shopMsgPush/subscribe/**") - .notMatch("/admin/coupon/grant") + SaRouter + // 完全开放的路径(不需要任何认证) + .match("/user/login", "/user/geo/**", "/user/home/**", + "/user/dict/**", "/user/openId","/admin/auth/**", + "/admin/shopMsgPush/subscribe/**", + "/admin/coupon/grant", + "/pay/**", + "/notify/**") + .stop() // 直接放行,不检查登录 + + // 用户认证路径 + .match("/user/**") + .check(r -> MyStpLogic.USER_LOGIC.checkLogin()) + + // 管理端认证(内网IP免认证) + .match("/**") .check(r -> { - ServletRequestAttributes attributes = - (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + ServletRequestAttributes attributes = (ServletRequestAttributes) + RequestContextHolder.getRequestAttributes(); if (attributes == null || (!ServletUtil.getClientIP(attributes.getRequest()).contains("192.168") && !ServletUtil.getClientIP(attributes.getRequest()).contains("127.0.0.1"))) { MyStpLogic.ADMIN_LOGIC.checkLogin(); } diff --git a/cash-common/cash-common-sa-token/src/main/java/com/czg/sa/MyStpLogic.java b/cash-common/cash-common-sa-token/src/main/java/com/czg/sa/MyStpLogic.java index cf76a8563..cb205f344 100644 --- a/cash-common/cash-common-sa-token/src/main/java/com/czg/sa/MyStpLogic.java +++ b/cash-common/cash-common-sa-token/src/main/java/com/czg/sa/MyStpLogic.java @@ -27,7 +27,7 @@ import java.util.function.Consumer; @Slf4j @Getter public class MyStpLogic { - public static final StpLogic CLIENT_LOGIC = new StpLogic("client"); + public static final StpLogic USER_LOGIC = new StpLogic("user"); public static final StpLogic ADMIN_LOGIC = new StpLogic("admin"); public Object isPC() { @@ -42,7 +42,7 @@ public class MyStpLogic { private StpLogic getLogic() { boolean hit = SaRouter.match("/user/**").isHit(); if (hit) { - return CLIENT_LOGIC; + return USER_LOGIC; } return ADMIN_LOGIC; }