【已解决】
使用注解的形式对参数值进行解密,通过拦截的方式修改request的参数值 继承HttpServletRequestWrapper 重写getParameter和getParameterMap 对值进行修改 debug模式下无法进入这两个方法
public class SecurityInterceptor implements Interceptor { @Override public void intercept(Invocation inv) { SecurityParameter parameter = inv.getMethod().getAnnotation(SecurityParameter.class); Controller c = inv.getController(); HttpServletRequest request= c.getRequest(); CustomWrapper customWrapper = null; if(parameter!=null){ if(parameter.inDecode()){ customWrapper = new CustomWrapper(request,new HashMap<String, Object>(inv.getController().getParaMap()),parameter.encrpet()); c.setHttpServletRequest(customWrapper); } } inv.invoke(); } }
这是CustomWrapper继承HttpServletRequestWrapper /*** 解决办法: * 重写getParameterValues 对参数的值进行修改 */ @Override public String[] getParameterValues(String name) { String[] value= pMap.get(name); if(null==value){ return null; } value = new String[]{format(value[0], encrpet)}; return value; } /** * 重写getParameterMap */ @SuppressWarnings("unchecked") @Override public Map<String, String[]> getParameterMap() { HashMap<String, String[]> paramMap = (HashMap<String, String[]>) super.getParameterMap(); paramMap = (HashMap<String, String[]>) paramMap.clone(); for (Iterator<?> iterator = paramMap.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, String[]> entry = (Map.Entry<String, String[]>) iterator.next(); String[] values = entry.getValue(); for (int i = 0; i < values.length; i++) { if (values[i] instanceof String) { values[i] = format(values[i], encrpet); } } entry.setValue(values); } return paramMap; }