package com.eshore.gringotts.web.configuration;

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.filter.SaServletFilter;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaHttpMethod;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * web配置
 *
 * @author lanyuanxiaoyao
 * @date 2024-11-14
 */
@Configuration
public class SaTokenConfiguration implements WebMvcConfigurer {
    private static final Logger logger = LoggerFactory.getLogger(SaTokenConfiguration.class);

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry
                .addInterceptor(
                        new SaInterceptor(handler -> {
                            SaRouter
                                    .match("/**")
                                    .notMatch("/")
                                    .notMatch("/index.html")
                                    .notMatch("/assets/**")
                                    .notMatch("/pages/**")
                                    .notMatch("/user/**")
                                    .check(r -> StpUtil.checkLogin());
                        })
                )
                .addPathPatterns("/**");
    }
}
