package com.example.JSiter;

import com.example.JSiter.filter.HTTPBasicAuthorizeAttribute;
import com.example.JSiter.filter.InitialFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;

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


@SpringBootApplication
public class JSiterApplication extends SpringBootServletInitializer {

    public JSiterApplication() {
    }

    public static void main(String[] args) {
        SpringApplication.run(JSiterApplication.class, args);
    }

    @Bean
    @Order(Integer.MIN_VALUE)
    public FilterRegistrationBean filterRegistrationBean2() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        InitialFilter initialFilter = new InitialFilter();
        registrationBean.setFilter(initialFilter);
        List<String> urlPatterns = new ArrayList();
        urlPatterns.add("/*");
        registrationBean.setUrlPatterns(urlPatterns);
        return registrationBean;
    }

    @Bean
    @Order(Integer.MAX_VALUE)
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        HTTPBasicAuthorizeAttribute httpBasicFilter = new HTTPBasicAuthorizeAttribute();
        registrationBean.setFilter(httpBasicFilter);
        List<String> urlPatterns = new ArrayList();
        urlPatterns.add("/app/*");
        registrationBean.setUrlPatterns(urlPatterns);
        return registrationBean;
    }
}