SpringCloud使用Filter过滤器实现@RequestParam参数加密
2020-12-13 05:43
标签:extends substr 扩展 com 方法 war xtend 调用 ini @WebFilter中的filterName首字母一定要小写!!! SpringCloud使用Filter过滤器实现@RequestParam参数加密 标签:extends substr 扩展 com 方法 war xtend 调用 ini 原文地址:https://blog.51cto.com/12012821/2417867package com.xiaohang.socialcard.pre.filter;
import com.xiaohang.socialcard.pre.utils.SM4Util;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@WebFilter(urlPatterns = {"/api/v1/get/getToken", "/api/v1/get/query", "/api/v1/get/page"}, filterName = "signAutheFilter")
public class SignAutheFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
String param = request.getParameter("param");
try {
param = SM4Util.encryptEcb("1234567890", param);
} catch (Exception e) {
e.printStackTrace();
}
MyRequestWrapper parameterRequestWrapper = new MyRequestWrapper(request);
parameterRequestWrapper.addParameter("param", param);
chain.doFilter(parameterRequestWrapper, res);// 替换原始请求参数
}
@Override
public void destroy() {
}
}
class MyRequestWrapper extends HttpServletRequestWrapper {
private Map
二、Application.class这里一定要加上ServletComponentScan注解用于扫描Filter过滤器
package com.xiaohang.socialcard.pre;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
@EnableFeignClients
@SpringBootApplication
@ServletComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
文章标题:SpringCloud使用Filter过滤器实现@RequestParam参数加密
文章链接:http://soscw.com/essay/31666.html