agent-skill-backend/src/main/java/com/kexue/skills/config/SaTokenConfig.java

45 lines
1.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.kexue.skills.config;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Sa-Token配置类
* @author
*/
@Configuration
public class SaTokenConfig implements WebMvcConfigurer {
/**
* 注册Sa-Token拦截器
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 添加Sa-Token拦截器校验规则为StpUtil.checkLogin()
registry.addInterceptor(new SaInterceptor(handler -> {
// 拦截所有请求,除了登录、注册、文档等不需要认证的接口
SaRouter
// 放行登录接口
.match("/api/login/**").stop()
// 放行注册接口
.match("/api/register/**").stop()
// 放行Swagger文档
.match("/doc.html").stop()
.match("/swagger-ui/**").stop()
.match("/v3/api-docs/**").stop()
// 放行静态资源
.match("/static/**").stop()
.match("/**/*.css").stop()
.match("/**/*.js").stop()
.match("/**/*.png").stop()
.match("/**/*.jpg").stop()
.match("/**/*.jpeg").stop()
// 其他请求需要登录
.check(() -> StpUtil.checkLogin());
})).addPathPatterns("/**");
}
}