检查登录

This commit is contained in:
2026-01-21 13:36:59 +08:00
parent 0345ab85ec
commit 0ba52b85b2
2 changed files with 21 additions and 17 deletions

View File

@@ -43,7 +43,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
userConfig.setIsShare(true); userConfig.setIsShare(true);
// config2.setTimeout(2000); // config2.setTimeout(2000);
userConfig.setTokenStyle("simple-uuid"); userConfig.setTokenStyle("simple-uuid");
MyStpLogic.CLIENT_LOGIC.setConfig(userConfig); MyStpLogic.USER_LOGIC.setConfig(userConfig);
} }
@PostConstruct @PostConstruct
@@ -62,21 +62,25 @@ public class SaTokenConfigure implements WebMvcConfigurer {
// 重置根路径防止satoken切割根路径导致匹配不到路径 // 重置根路径防止satoken切割根路径导致匹配不到路径
ApplicationInfo.routePrefix = ""; ApplicationInfo.routePrefix = "";
SaRouter.match("/user/**").notMatch("/user/login", "/user/test", "/user/geo/**", "/user/home/**", "/user/home/**", "/user/dict/**", "/user/openId") SaRouter
.notMatch("/pay/**") // 完全开放的路径(不需要任何认证)
.notMatch("/notify/**") .match("/user/login", "/user/geo/**", "/user/home/**",
.check(r -> MyStpLogic.CLIENT_LOGIC.checkLogin()) "/user/dict/**", "/user/openId","/admin/auth/**",
.setHit(true) "/admin/shopMsgPush/subscribe/**",
// .match("/**") "/admin/coupon/grant",
.notMatch("/user/**") "/pay/**",
.notMatch("/pay/**") "/notify/**")
.notMatch("/notify/**") .stop() // 直接放行,不检查登录
.notMatch("/admin/auth/**")
.notMatch("/admin/shopMsgPush/subscribe/**") // 用户认证路径
.notMatch("/admin/coupon/grant") .match("/user/**")
.check(r -> MyStpLogic.USER_LOGIC.checkLogin())
// 管理端认证内网IP免认证
.match("/**")
.check(r -> { .check(r -> {
ServletRequestAttributes attributes = ServletRequestAttributes attributes = (ServletRequestAttributes)
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); RequestContextHolder.getRequestAttributes();
if (attributes == null || (!ServletUtil.getClientIP(attributes.getRequest()).contains("192.168") && !ServletUtil.getClientIP(attributes.getRequest()).contains("127.0.0.1"))) { if (attributes == null || (!ServletUtil.getClientIP(attributes.getRequest()).contains("192.168") && !ServletUtil.getClientIP(attributes.getRequest()).contains("127.0.0.1"))) {
MyStpLogic.ADMIN_LOGIC.checkLogin(); MyStpLogic.ADMIN_LOGIC.checkLogin();
} }

View File

@@ -27,7 +27,7 @@ import java.util.function.Consumer;
@Slf4j @Slf4j
@Getter @Getter
public class MyStpLogic { 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 static final StpLogic ADMIN_LOGIC = new StpLogic("admin");
public Object isPC() { public Object isPC() {
@@ -42,7 +42,7 @@ public class MyStpLogic {
private StpLogic getLogic() { private StpLogic getLogic() {
boolean hit = SaRouter.match("/user/**").isHit(); boolean hit = SaRouter.match("/user/**").isHit();
if (hit) { if (hit) {
return CLIENT_LOGIC; return USER_LOGIC;
} }
return ADMIN_LOGIC; return ADMIN_LOGIC;
} }