package com.securitycontrol.common.security.config;

import com.securitycontrol.common.security.interceptor.ParamSecureHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.securitycontrol.common.security.interceptor.HeaderInterceptor;

/**
 * 拦截器配置
 *
 * @author czc
 */
@Configuration
@Component
public class WebMvcConfig implements WebMvcConfigurer
{
    /** 不需要拦截地址 */
    public static final String[] EXCLUDE_URLS = { "/login/**","/userLogin/**","/sys/sysLog/saveLogs", "/logout", "/refresh","/getUserTicket","/sys/logs/saveLogs","/error","/sys/select/**" };
    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        registry.addInterceptor(getHeaderInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(EXCLUDE_URLS)
                .order(-10);
        registry.addInterceptor(getParamSecureInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(EXCLUDE_URLS)
                .order(-10);
    }



    /**
     * 自定义请求头拦截器
     */
    @Bean
    public HeaderInterceptor getHeaderInterceptor()
    {
        return new HeaderInterceptor();
    }


    /**
     * 自定义参数拦截器
     */
    @Bean
    public ParamSecureHandler getParamSecureInterceptor()
    {
        return new ParamSecureHandler();
    }

}
