yyt
2024-06-26 0cceb649e1dc443c2a91d26d81eacb0867c96db3
提交 | 用户 | 时间
0cceb6 1 package com.jcdm.framework.config;
Y 2
3 import java.util.HashMap;
4 import java.util.Map;
5 import javax.servlet.DispatcherType;
6 import org.springframework.beans.factory.annotation.Value;
7 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
8 import org.springframework.boot.web.servlet.FilterRegistrationBean;
9 import org.springframework.context.annotation.Bean;
10 import org.springframework.context.annotation.Configuration;
11 import com.jcdm.common.filter.RepeatableFilter;
12 import com.jcdm.common.filter.XssFilter;
13 import com.jcdm.common.utils.StringUtils;
14
15 /**
16  * Filter配置
17  *
18  * @author jc
19  */
20 @Configuration
21 public class FilterConfig
22 {
23     @Value("${xss.excludes}")
24     private String excludes;
25
26     @Value("${xss.urlPatterns}")
27     private String urlPatterns;
28
29     @SuppressWarnings({ "rawtypes", "unchecked" })
30     @Bean
31     @ConditionalOnProperty(value = "xss.enabled", havingValue = "true")
32     public FilterRegistrationBean xssFilterRegistration()
33     {
34         FilterRegistrationBean registration = new FilterRegistrationBean();
35         registration.setDispatcherTypes(DispatcherType.REQUEST);
36         registration.setFilter(new XssFilter());
37         registration.addUrlPatterns(StringUtils.split(urlPatterns, ","));
38         registration.setName("xssFilter");
39         registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE);
40         Map<String, String> initParameters = new HashMap<String, String>();
41         initParameters.put("excludes", excludes);
42         registration.setInitParameters(initParameters);
43         return registration;
44     }
45
46     @SuppressWarnings({ "rawtypes", "unchecked" })
47     @Bean
48     public FilterRegistrationBean someFilterRegistration()
49     {
50         FilterRegistrationBean registration = new FilterRegistrationBean();
51         registration.setFilter(new RepeatableFilter());
52         registration.addUrlPatterns("/*");
53         registration.setName("repeatableFilter");
54         registration.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE);
55         return registration;
56     }
57
58 }