提交 644b7772 作者: 方治民

feat: 新增 @AuthIgnore 注解, 忽略接口鉴权

上级 b0fef6c5
/* (C) 2022 YiRing, Inc. */
package com.yiring.auth.annotation;
import java.lang.annotation.*;
/**
* 忽略登录校验
* 与 @SaCheckLogin 相对
*
* @author Jim
* @version 0.1
* 2022/4/7 15:21
*/
@SuppressWarnings({ "unused" })
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface AuthIgnore {
}
...@@ -5,7 +5,9 @@ import cn.dev33.satoken.interceptor.SaRouteInterceptor; ...@@ -5,7 +5,9 @@ import cn.dev33.satoken.interceptor.SaRouteInterceptor;
import cn.dev33.satoken.router.SaHttpMethod; import cn.dev33.satoken.router.SaHttpMethod;
import cn.dev33.satoken.router.SaRouter; import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import com.yiring.auth.annotation.AuthIgnore;
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;
...@@ -34,11 +36,16 @@ public class SaTokenConfigure implements WebMvcConfigurer { ...@@ -34,11 +36,16 @@ public class SaTokenConfigure implements WebMvcConfigurer {
// TODO // TODO
// .notMatch("/**") // .notMatch("/**")
// 示例接口 // 示例接口
.notMatch("/example/**") // .notMatch("/example/**")
// 授权相关接口(登录、登出、注册等) // 授权相关接口(登录、登出、注册等)
.notMatch("/auth/**") .notMatch("/auth/**")
.notMatch("/favicon.ico", "/**/*.html", "/**/*.js", "/**/*.css") .notMatch("/favicon.ico", "/**/*.html", "/**/*.js", "/**/*.css")
.notMatch("/v2/api-docs/**", "/v3/api-docs/**", "/swagger-resources/**") .notMatch("/v2/api-docs/**", "/v3/api-docs/**", "/swagger-resources/**")
// 自定义注解忽略接口鉴权
.notMatch(r -> {
HandlerMethod method = (HandlerMethod) handler;
return method.hasMethodAnnotation(AuthIgnore.class);
})
.check(r -> StpUtil.checkLogin()); .check(r -> StpUtil.checkLogin());
}) })
) )
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论