|
|
|
@ -9,11 +9,6 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import com.google.common.collect.Maps; |
|
|
|
import com.zdxt.auth.common.utils.StringUtils; |
|
|
|
import com.zdxt.auth.common.xss.XssFilter; |
|
|
|
import org.springframework.web.cors.CorsConfiguration; |
|
|
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
|
|
|
import org.springframework.web.filter.CorsFilter; |
|
|
|
|
|
|
|
/** |
|
|
|
* Filter配置 |
|
|
|
@ -36,9 +31,11 @@ public class FilterConfig |
|
|
|
@Autowired |
|
|
|
HostFilter hostFilter; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private FileTypeFilter fileTypeFilter; |
|
|
|
|
|
|
|
/** |
|
|
|
* 防止xss攻击 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" }) |
|
|
|
@Bean |
|
|
|
public FilterRegistrationBean xssFilterRegistration() |
|
|
|
@ -46,8 +43,8 @@ public class FilterConfig |
|
|
|
FilterRegistrationBean registration = new FilterRegistrationBean(); |
|
|
|
registration.setDispatcherTypes(DispatcherType.REQUEST); |
|
|
|
registration.setFilter(new XssAndSqlFilter()); |
|
|
|
registration.addUrlPatterns(StringUtils.split(urlPatterns, ",")); |
|
|
|
registration.setName("xssFilter"); |
|
|
|
registration.addUrlPatterns("/*"); |
|
|
|
registration.setName("xssAndSqlFilter"); |
|
|
|
registration.setOrder(Integer.MAX_VALUE); |
|
|
|
Map<String, String> initParameters = Maps.newHashMap(); |
|
|
|
initParameters.put("excludes", excludes); |
|
|
|
@ -66,22 +63,5 @@ public class FilterConfig |
|
|
|
return registration; |
|
|
|
} |
|
|
|
|
|
|
|
// @Bean
|
|
|
|
// public FilterRegistrationBean corsNewFilter() {
|
|
|
|
// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
|
|
// CorsConfiguration config = new CorsConfiguration();
|
|
|
|
// config.setAllowCredentials(true);
|
|
|
|
// config.addAllowedOrigin("http://10.132.108.3:85");
|
|
|
|
// config.addAllowedOrigin("http://10.132.108.3:80");
|
|
|
|
// config.addAllowedOrigin("http://10.132.108.3:81");
|
|
|
|
// config.addAllowedOrigin("http://192.168.244.1:3301");
|
|
|
|
// config.addAllowedHeader("*");
|
|
|
|
// config.addAllowedMethod("*");
|
|
|
|
// source.registerCorsConfiguration("/**", config); // CORS 配置对所有接口都有效
|
|
|
|
// FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
|
|
|
|
// bean.setOrder(0);
|
|
|
|
// return bean;
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|