content: package com.admin4j.framework.xss.wrapper;
  
   
  import com.admin4j.framework.xss.utils.XssUtils;
  import lombok.extern.slf4j.Slf4j;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletRequestWrapper;
  import java.util.List;
  import java.util.Map;
  
  /**
   * 跨站攻击请求包装器
   *
   * @author andanyang
   * @since 2021/10/22 16:11
   */
  @Slf4j
  public class XssRequestWrapper extends HttpServletRequestWrapper {
  
      private List<String> ignoreParamValueList;
  
      public XssRequestWrapper(HttpServletRequest request, List<String> ignoreParamValueList) {
          super(request);
          this.ignoreParamValueList = ignoreParamValueList;
      }
  
      @Override
      public Map<String, String[]> getParameterMap() {
          Map<String, String[]> requestMap = super.getParameterMap();
          for (Map.Entry<String, String[]> me : requestMap.entrySet()) {
              log.debug(me.getKey() + ":");
              String[] values = me.getValue();
              for (int i = 0; i < values.length; i++) {
                  log.debug(values[i]);
                  values[i] = XssUtils.xssClean(values[i], this.ignoreParamValueList);
              }
          }
          return requestMap;
      }
  
  
      @Override
      public String[] getParameterValues(String paramString) {
          String[] arrayOfString1 = super.getParameterValues(paramString);
          if (arrayOfString1 == null) {
              return null;
          }
          int i = arrayOfString1.length;
          String[] arrayOfString2 = new String[i];
          for (int j = 0; j < i; j++) {
              arrayOfString2[j] = XssUtils.xssClean(arrayOfString1[j], this.ignoreParamValueList);
          }
          return arrayOfString2;
      }
  
      @Override
      public String getParameter(String paramString) {
          String str = super.getParameter(paramString);
          if (str == null) {
              return null;
          }
          return XssUtils.xssClean(str, this.ignoreParamValueList);
      }
  
      @Override
      public String getHeader(String paramString) {
          String str = super.getHeader(paramString);
          if (str == null) {
              return null;
          }
          return XssUtils.xssClean(str, this.ignoreParamValueList);
      }
  }
  