package com.sptg.gateway.cfgbeans;

import com.sptg.common.core.filter.EncryptionFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

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

/**
 * title: WebConfigBean
 * package: com.sptg.gateway.cfgbeans
 * description: Web配置类
 *
 *
 *
 */
@Configuration
public class WebConfigBean {

    /**
     * 功能描述: 配置加解密过滤器
     * @return FilterRegistrationBean
     *
     *
     */
    @Bean
    public FilterRegistrationBean encryptionFilter(){
        EncryptionFilter encryptionFilter = new EncryptionFilter();
        //初始化 --- 过滤不需要拦截的请求
        List<String> excludeList = new ArrayList<>();
        excludeList.add("/app/permissions/dict/getByCode");
        encryptionFilter.setExcludeList(excludeList);
        FilterRegistrationBean registration = new FilterRegistrationBean();
        //  注册过滤器
        registration.setFilter(encryptionFilter);
        //  拦截全部请求
        registration.addUrlPatterns("/*");
        //  设置过滤器名称
        registration.setName(encryptionFilter.getClass().getSimpleName());
        return registration;
    }
}
