packagecom.joppay.admin.security.xss;importcom.fasterxml.jackson.databind.ObjectMapper;importcom.fasterxml.jackson.databind.module.SimpleModule;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Primary;importorg.springframework.core.annotation.Order;importorg.springframework.http.MediaType;importorg.springframework.http.converter.json.Jackson2ObjectMapperBuilder;importorg.springframework.http.converter.json.MappingJackson2HttpMessageConverter;importorg.springframework.stereotype.Component;import javax.servlet.*;importjavax.servlet.annotation.WebFilter;importjavax.servlet.http.HttpServletRequest;importjava.io.IOException;importjava.util.ArrayList;importjava.util.List;/*** XSS过滤
*
*@authorleroy
* @date 2019/3/6 18:13*/@WebFilter
@Componentpublic class XssFilter implementsFilter {
FilterConfig filterConfig= null;
@Overridepublic void init(FilterConfig filterConfig) throwsServletException {this.filterConfig =filterConfig;
}
@Overridepublic void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throwsIOException, ServletException {
HttpServletRequest req=(HttpServletRequest) request;
XssHttpServletRequestWrapper xssRequestWrapper= newXssHttpServletRequestWrapper(req);
chain.doFilter(xssRequestWrapper, response);
}
@Overridepublic voiddestroy() {this.filterConfig = null;
}
@BeanpublicMappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {return newXSSMappingJackson2HttpMessageConverter();
}
@BeanpublicXssStringJsonSerializer xssStringJsonSerializer(){return newXssStringJsonSerializer();
}
}