package cn.palmte.work.config;

import cn.palmte.work.security.ReplaceSpecialCharFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.jfunc.http.SmartHttpClient;
import top.jfunc.http.smart.JdkSmartHttpClient;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xiongshiyan at 2020/9/30 , contact me with email yanshixiong@126.com or phone 15208384257
 */
@Configuration
public class HttpConfig {
    @Bean
    public SmartHttpClient smartHttpClient(){
        return new JdkSmartHttpClient();
    }


    /**
     * xss过滤拦截器
     */
    @Bean
    public FilterRegistrationBean xssFilterRegistrationBean() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new ReplaceSpecialCharFilter());
        filterRegistrationBean.setOrder(1);
        filterRegistrationBean.setEnabled(true);
        filterRegistrationBean.addUrlPatterns("/*");
        Map<String, String> initParameters = new HashMap<>();
        initParameters.put("includes", "/fourcal/admin/err");
        filterRegistrationBean.setInitParameters(initParameters);
        return filterRegistrationBean;
    }

}
