package com.chinaweal.aiccs.config;

import com.chinaweal.youfool.framework.springboot.filter.RepeatlyReadFilter;
import com.chinaweal.youfool.framework.springboot.log.filter.RestLogFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author itluck
 */
@Configuration
public class FilterConfig {
    /**
     * 日志记录过滤器
     */
    @Bean
    public FilterRegistrationBean<RestLogFilter> restLogFilter() {
        FilterRegistrationBean<RestLogFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new RestLogFilter());
        registrationBean.addUrlPatterns("/*");
        registrationBean.setName("restLogFilter");
        registrationBean.setOrder(-99);
        return registrationBean;
    }

    /**
     * 开启重复读取request流，用于日志
     */
    @Bean
    public FilterRegistrationBean<RepeatlyReadFilter> repeatlyReadFilter() {
        FilterRegistrationBean<RepeatlyReadFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new RepeatlyReadFilter());
        registrationBean.addUrlPatterns("/*");
        registrationBean.setName("repeatlyReadFilter");
        registrationBean.setOrder(-100);
        return registrationBean;
    }

    /**
     * IMS请求编码预处理过滤器
     */
    @Bean
    public FilterRegistrationBean<ImsRequestFilter> imsRequestFilter() {
        FilterRegistrationBean<ImsRequestFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new ImsRequestFilter());
        registrationBean.addUrlPatterns("/ims/*");
        registrationBean.setName("imsRequestFilter");
        registrationBean.setOrder(-101);
        return registrationBean;
    }
}
