package com.hs.admin.common.configurations;

import com.hs.admin.common.intercepters.LoginInterceptor;
import org.springframework.boot.context.properties.ConfigurationProperties;
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;

import java.util.ArrayList;
import java.util.List;

@Configuration
@ConfigurationProperties(prefix = "config.path")
public class LoginConfigure implements WebMvcConfigurer {
    /**
     * 需要登录的拦截路由
     */
    private List<String> include = new ArrayList<>();
    /**
     * 排除登录的拦截路由
     */
    private List<String> exclude = new ArrayList<>();

    public void setInclude(List<String> include) {
        this.include = include;
    }

    public void setExclude(List<String> exclude) {
        this.exclude = exclude;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginIntercepter()).addPathPatterns(include).excludePathPatterns(exclude);

        WebMvcConfigurer.super.addInterceptors(registry);
    }

    @Bean
    public LoginInterceptor loginIntercepter() {
        return new LoginInterceptor();
    }
}
