|
@@ -1,8 +1,10 @@
|
|
|
package com.kym.admin.config;
|
|
package com.kym.admin.config;
|
|
|
|
|
|
|
|
|
|
+import cn.dev33.satoken.annotation.SaIgnore;
|
|
|
import cn.dev33.satoken.interceptor.SaInterceptor;
|
|
import cn.dev33.satoken.interceptor.SaInterceptor;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
+import org.springframework.web.method.HandlerMethod;
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
|
@@ -17,7 +19,16 @@ public class SaTokenConfigure 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(handler -> {
|
|
|
|
|
+ // 检查 @SaIgnore 注解,有则跳过鉴权
|
|
|
|
|
+ if (handler instanceof HandlerMethod hm) {
|
|
|
|
|
+ if (hm.hasMethodAnnotation(SaIgnore.class)
|
|
|
|
|
+ || hm.getBeanType().isAnnotationPresent(SaIgnore.class)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ StpUtil.checkLogin();
|
|
|
|
|
+ }))
|
|
|
.addPathPatterns("/**")
|
|
.addPathPatterns("/**")
|
|
|
// login接口不鉴权
|
|
// login接口不鉴权
|
|
|
.excludePathPatterns(
|
|
.excludePathPatterns(
|