package com.jy.framework.satoken;

import com.jy.framework.config.JyConfig;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 权限安全配置
 */

@Slf4j
@Configuration
public class SecurityConfig implements WebMvcConfigurer {

    @Resource
    private JyConfig jyConfig;

    @Resource
    private JySaInterceptor jySaInterceptor;

    /**
     * 注册sa-token的拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册路由拦截器，自定义验证规则
        registry.addInterceptor(jySaInterceptor)
                .addPathPatterns("/**")
                // 排除不需要拦截的路径
                .excludePathPatterns(jyConfig.getOpenUrl());
    }

}
