package egovframework.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * XSS 필터 설정 클래스
 */
@Configuration
public class XssFilterConfig {

    private final XssUtil xssUtil;

    public XssFilterConfig(XssUtil xssUtil) {
        this.xssUtil = xssUtil;
    }

    /**
     * XSS 필터 등록
     * @return FilterRegistrationBean
     */
    @Bean
    public FilterRegistrationBean<XssFilter> xssFilterRegistration() {
        FilterRegistrationBean<XssFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new XssFilter(xssUtil));
        registrationBean.addUrlPatterns("/*"); // 모든 URL에 적용
        registrationBean.setName("xssFilter");
        registrationBean.setOrder(1); // 필터 순서 (낮은 숫자가 먼저 실행)
        return registrationBean;
    }
}