package com.hdkj.lt.si.config;

import com.google.common.collect.Lists;
import com.hdkj.lt.si.filter.AuthenticationFilter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.Filter;

/**
 * @Description:
 * @Author: wenhao
 * @Create: 2024/03/22 16:05
 * @Version: 1.0
 */
@Configuration
public class WebConfiguration implements WebMvcConfigurer {

    @Bean(AuthenticationFilter.FILTER_NAME)
    public Filter authenticationFilter() {
        return new AuthenticationFilter();
    }

    @Bean
    public FilterRegistrationBean<Filter> filterRegistrationBean(@Qualifier(AuthenticationFilter.FILTER_NAME) Filter filter) {
        FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
        registration.setFilter(filter);
        registration.setUrlPatterns(Lists.newArrayList("/ext/*"));
        registration.setName(AuthenticationFilter.FILTER_NAME);
        registration.setOrder(1);
        return registration;
    }

}
