mirror of
				https://github.com/continew-org/continew-starter.git
				synced 2025-10-31 22:57:19 +08:00 
			
		
		
		
	refactor(auth/satoken): 支持更灵活的动态化路由拦截鉴权
因为 lambda 表达式之外的代码只会在启动时执行一次,所以 excludePaths() 方法是无法做到动态化读取的, 若要在项目运行时动态读写,必须把调用 excludePaths() 的时机放在 lambda 里。
This commit is contained in:
		| @@ -18,6 +18,7 @@ package top.charles7c.continew.starter.auth.satoken.autoconfigure; | |||||||
|  |  | ||||||
| import cn.dev33.satoken.interceptor.SaInterceptor; | import cn.dev33.satoken.interceptor.SaInterceptor; | ||||||
| import cn.dev33.satoken.jwt.StpLogicJwtForSimple; | import cn.dev33.satoken.jwt.StpLogicJwtForSimple; | ||||||
|  | import cn.dev33.satoken.router.SaRouter; | ||||||
| import cn.dev33.satoken.stp.StpInterface; | import cn.dev33.satoken.stp.StpInterface; | ||||||
| import cn.dev33.satoken.stp.StpLogic; | import cn.dev33.satoken.stp.StpLogic; | ||||||
| import cn.dev33.satoken.stp.StpUtil; | import cn.dev33.satoken.stp.StpUtil; | ||||||
| @@ -59,9 +60,9 @@ public class SaTokenAutoConfiguration implements WebMvcConfigurer { | |||||||
|     @Override |     @Override | ||||||
|     public void addInterceptors(InterceptorRegistry registry) { |     public void addInterceptors(InterceptorRegistry registry) { | ||||||
|         // 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验 |         // 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验 | ||||||
|         registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin())) |         registry.addInterceptor(new SaInterceptor(handle -> SaRouter.match(StringConstants.PATH_PATTERN) | ||||||
|             .addPathPatterns(StringConstants.PATH_PATTERN) |             .notMatch(properties.getSecurity().getExcludes()) | ||||||
|             .excludePathPatterns(properties.getSecurity().getExcludes()); |             .check(r -> StpUtil.checkLogin()))).addPathPatterns(StringConstants.PATH_PATTERN); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user