cn.jiangzeyin.common.request.MultipartParameterXssWrapper Maven / Gradle / Ivy
package cn.jiangzeyin.common.request;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.Map;
/**
* 文件上传拦截器
*
* @author jiangzeyin
* @date 2018/8/21.
*/
public class MultipartParameterXssWrapper extends StandardMultipartHttpServletRequest {
private final Map parameters;
public MultipartParameterXssWrapper(HttpServletRequest request) throws MultipartException {
super(request);
// 获取请求头编码
Charset charset = ParameterXssWrapper.getCharset(request);
parameters = XssFilter.doXss(super.getParameterMap(), charset);
}
@Override
public Enumeration getParameterNames() {
return super.getParameterNames();
}
@Override
public Map getParameterMap() {
return parameters;
}
@Override
public String getParameter(String name) {
String[] values = getParameterValues(name);
if (values == null) {
return null;
}
return ArrayUtil.join(values, StrUtil.COMMA);
}
@Override
public String[] getParameterValues(String name) {
if (parameters == null) {
return null;
}
return parameters.get(name);
}
}