|
|
@ -2,10 +2,12 @@ package com.ruoyi.framework.config;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import javax.servlet.DispatcherType;
|
|
|
|
import javax.servlet.DispatcherType;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
|
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
import com.ruoyi.common.xss.XssFilter;
|
|
|
|
import com.ruoyi.common.xss.XssFilter;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -16,6 +18,15 @@ import com.ruoyi.common.xss.XssFilter;
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
public class FilterConfig
|
|
|
|
public class FilterConfig
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
@Value("${xss.enabled}")
|
|
|
|
|
|
|
|
private String enabled;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${xss.excludes}")
|
|
|
|
|
|
|
|
private String excludes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${xss.urlPatterns}")
|
|
|
|
|
|
|
|
private String urlPatterns;
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public FilterRegistrationBean xssFilterRegistration()
|
|
|
|
public FilterRegistrationBean xssFilterRegistration()
|
|
|
@ -23,12 +34,12 @@ public class FilterConfig
|
|
|
|
FilterRegistrationBean registration = new FilterRegistrationBean();
|
|
|
|
FilterRegistrationBean registration = new FilterRegistrationBean();
|
|
|
|
registration.setDispatcherTypes(DispatcherType.REQUEST);
|
|
|
|
registration.setDispatcherTypes(DispatcherType.REQUEST);
|
|
|
|
registration.setFilter(new XssFilter());
|
|
|
|
registration.setFilter(new XssFilter());
|
|
|
|
registration.addUrlPatterns("/*");
|
|
|
|
registration.addUrlPatterns(StringUtils.split(urlPatterns, ","));
|
|
|
|
registration.setName("xssFilter");
|
|
|
|
registration.setName("xssFilter");
|
|
|
|
registration.setOrder(Integer.MAX_VALUE);
|
|
|
|
registration.setOrder(Integer.MAX_VALUE);
|
|
|
|
Map<String, String> initParameters = Maps.newHashMap();
|
|
|
|
Map<String, String> initParameters = Maps.newHashMap();
|
|
|
|
initParameters.put("excludes", "/system/notice/*,/img/*,/css/*,/fonts/*,/js/*,/ajax/*,/ruoyi/*");
|
|
|
|
initParameters.put("excludes", excludes);
|
|
|
|
initParameters.put("xssEbabled", "false");
|
|
|
|
initParameters.put("enabled", enabled);
|
|
|
|
registration.setInitParameters(initParameters);
|
|
|
|
registration.setInitParameters(initParameters);
|
|
|
|
return registration;
|
|
|
|
return registration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|