package com.bonus.common.security.config;

//import com.bonus.common.security.interceptor.ParamSecureHandler;
import com.bonus.common.security.interceptor.ParamSecureHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.bonus.common.security.interceptor.HeaderInterceptor;

/**
 * 拦截器配置
 *
 * @author bonus
 */
public class WebMvcConfig implements WebMvcConfigurer
{
    /** 不需要拦截地址  "/logout",*/
    public static final String[] EXCLUDEURLS = { "/login",  "/refresh" };

    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        registry.addInterceptor(getHeaderInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(EXCLUDEURLS)
                .order(-10);
        //自定义拦截器
        registry.addInterceptor(getParamSecureInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(EXCLUDEURLS)
                .order(-10);

    }

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


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

}
