|
@@ -1,8 +1,10 @@
|
|
|
package com.kym.miniapp.config;
|
|
package com.kym.miniapp.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;
|
|
|
|
|
|
|
@@ -13,13 +15,18 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
*/
|
|
*/
|
|
|
@Configuration
|
|
@Configuration
|
|
|
public class SaTokenConfigure implements WebMvcConfigurer {
|
|
public class SaTokenConfigure implements WebMvcConfigurer {
|
|
|
- // 注册拦截器
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
|
- // 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。
|
|
|
|
|
- registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
|
|
|
|
|
|
|
+ registry.addInterceptor(new SaInterceptor(handler -> {
|
|
|
|
|
+ if (handler instanceof HandlerMethod hm) {
|
|
|
|
|
+ if (hm.hasMethodAnnotation(SaIgnore.class)
|
|
|
|
|
+ || hm.getBeanType().isAnnotationPresent(SaIgnore.class)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ StpUtil.checkLogin();
|
|
|
|
|
+ }))
|
|
|
.addPathPatterns("/**")
|
|
.addPathPatterns("/**")
|
|
|
- // 以下接口不鉴权 更新:弃用,使用@SaIgnore注解替代
|
|
|
|
|
.excludePathPatterns("/parking-coupon/**");
|
|
.excludePathPatterns("/parking-coupon/**");
|
|
|
}
|
|
}
|
|
|
|
|
|