优化 GET 方法响应体支持加密
This commit is contained in:
parent
0974e65c0a
commit
c9cb308abf
@ -36,8 +36,9 @@ public class CryptoFilter implements Filter {
|
|||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||||
HttpServletRequest servletRequest = (HttpServletRequest) request;
|
HttpServletRequest servletRequest = (HttpServletRequest) request;
|
||||||
HttpServletResponse servletResponse = (HttpServletResponse) response;
|
HttpServletResponse servletResponse = (HttpServletResponse) response;
|
||||||
|
// 获取加密注解
|
||||||
boolean responseFlag = false;
|
ApiEncrypt apiEncrypt = this.getApiEncryptAnnotation(servletRequest);
|
||||||
|
boolean responseFlag = apiEncrypt != null && apiEncrypt.response();
|
||||||
ServletRequest requestWrapper = null;
|
ServletRequest requestWrapper = null;
|
||||||
ServletResponse responseWrapper = null;
|
ServletResponse responseWrapper = null;
|
||||||
EncryptResponseBodyWrapper responseBodyWrapper = null;
|
EncryptResponseBodyWrapper responseBodyWrapper = null;
|
||||||
@ -48,9 +49,6 @@ public class CryptoFilter implements Filter {
|
|||||||
if (HttpMethod.PUT.matches(servletRequest.getMethod()) || HttpMethod.POST.matches(servletRequest.getMethod())) {
|
if (HttpMethod.PUT.matches(servletRequest.getMethod()) || HttpMethod.POST.matches(servletRequest.getMethod())) {
|
||||||
// 是否存在加密标头
|
// 是否存在加密标头
|
||||||
String headerValue = servletRequest.getHeader(properties.getHeaderFlag());
|
String headerValue = servletRequest.getHeader(properties.getHeaderFlag());
|
||||||
// 获取加密注解
|
|
||||||
ApiEncrypt apiEncrypt = this.getApiEncryptAnnotation(servletRequest);
|
|
||||||
responseFlag = apiEncrypt != null && apiEncrypt.response();
|
|
||||||
if (StringUtils.isNotBlank(headerValue)) {
|
if (StringUtils.isNotBlank(headerValue)) {
|
||||||
// 请求解密
|
// 请求解密
|
||||||
requestWrapper = new DecryptRequestBodyWrapper(servletRequest, properties.getPrivateKey(), properties.getHeaderFlag());
|
requestWrapper = new DecryptRequestBodyWrapper(servletRequest, properties.getPrivateKey(), properties.getHeaderFlag());
|
||||||
@ -64,13 +62,13 @@ public class CryptoFilter implements Filter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// 判断是否响应加密
|
// 判断是否响应加密
|
||||||
if (responseFlag) {
|
if (responseFlag) {
|
||||||
responseBodyWrapper = new EncryptResponseBodyWrapper(servletResponse);
|
responseBodyWrapper = new EncryptResponseBodyWrapper(servletResponse);
|
||||||
responseWrapper = responseBodyWrapper;
|
responseWrapper = responseBodyWrapper;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
chain.doFilter(
|
chain.doFilter(
|
||||||
ObjectUtil.defaultIfNull(requestWrapper, request),
|
ObjectUtil.defaultIfNull(requestWrapper, request),
|
||||||
|
Loading…
Reference in New Issue
Block a user