/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved.
 * <a>http://www.crunii.com</a>
 */
package com.crunii.micro.config;

import java.util.Arrays;
import java.util.List;

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

import com.crunii.micro.common.web.filter.XssFilter;

/**
 * @author 田平 create 2021/5/19 15:09
 */
@Configuration
@ConditionalOnProperty(name = "xss.protection.enabled", havingValue = "true", matchIfMissing = false)
public class XssConfiguration {

	@Bean
	public FilterRegistrationBean<XssFilter> regXssFilter() {
		FilterRegistrationBean<XssFilter> registrationBean = new FilterRegistrationBean<>();
		registrationBean.setName("xss");
		registrationBean.setOrder(1);
		registrationBean.setFilter(new XssFilter());
		List<String> urlPatterns = Arrays.asList("/*");
		registrationBean.setUrlPatterns(urlPatterns);
		return registrationBean;
	}

}
