管理端用户端权限隔离
This commit is contained in:
@@ -54,14 +54,15 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
// 重置根路径,防止satoken切割根路径导致匹配不到路径
|
||||
ApplicationInfo.routePrefix = "";
|
||||
|
||||
SaRouter.match("/**").notMatch("/user/login", "/admin/auth/**")
|
||||
.check(r -> StpKit.USER.checkLogin());
|
||||
// .setHit(true)
|
||||
SaRouter.match("/user/**").notMatch("/user/login", "/user/test")
|
||||
.check(r -> StpKit.USER.checkMiniUser())
|
||||
.setHit(true)
|
||||
// .match("/**")
|
||||
// .notMatch("/user/**")
|
||||
// .notMatch("/admin/auth/**")
|
||||
// .notMatch("/admin/feign/**")
|
||||
// .check(r -> StpKit.ADMIN.checkLogin());
|
||||
.notMatch("/user/**")
|
||||
.notMatch("/admin/auth/**")
|
||||
.notMatch("/admin/feign/**")
|
||||
.check(r -> StpKit.USER.checkManager());
|
||||
|
||||
})).addPathPatterns("/**");
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.czg.sa;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.exception.NotPermissionException;
|
||||
import cn.dev33.satoken.session.SaSession;
|
||||
import cn.dev33.satoken.stp.StpLogic;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -69,6 +71,28 @@ public class MyStpLogic extends StpLogic {
|
||||
return shopId == null ? defaultVal : shopId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验是否为管理端登录
|
||||
*/
|
||||
public void checkManager() {
|
||||
StpKit.USER.checkLogin();
|
||||
Object object = StpKit.USER.getSession().get("isManager");
|
||||
if (object instanceof Boolean t && !t) {
|
||||
throw new NotPermissionException("权限不足");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验是否为小程序登录
|
||||
*/
|
||||
public void checkMiniUser() {
|
||||
StpKit.USER.checkLogin();
|
||||
Object object = StpKit.USER.getSession().get("isManager");
|
||||
if (object instanceof Boolean t && t) {
|
||||
throw new NotPermissionException("权限不足");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为管理员
|
||||
* @return 布尔值
|
||||
|
||||
Reference in New Issue
Block a user