mirror of
https://gitee.com/incloudcode/yexuejc-springboot.git
synced 2025-07-12 23:12:45 +08:00
2.0.6 升级依赖
This commit is contained in:
parent
0e1fd35a85
commit
83a20b010b
@ -11,6 +11,7 @@ spring-boot-starter-parent:2.0.5.RELEASE
|
|||||||
```
|
```
|
||||||
**update:** <br/>
|
**update:** <br/>
|
||||||
1. 升级依赖
|
1. 升级依赖
|
||||||
|
2. 出入参加密 ParamsRequestBodyAdvice/ParamsResponseBodyAdvice 增加开关(默认关)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -9,6 +9,7 @@ import com.yexuejc.springboot.base.exception.GatewayException;
|
|||||||
import com.yexuejc.springboot.base.util.LogUtil;
|
import com.yexuejc.springboot.base.util.LogUtil;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@ -35,6 +36,7 @@ import java.security.interfaces.RSAPrivateKey;
|
|||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
@ConditionalOnClass({RequestBodyAdvice.class, HttpHeaders.class, HttpInputMessage.class, HttpMessageConverter.class})
|
@ConditionalOnClass({RequestBodyAdvice.class, HttpHeaders.class, HttpInputMessage.class, HttpMessageConverter.class})
|
||||||
@EnableConfigurationProperties(RsaProperties.class)
|
@EnableConfigurationProperties(RsaProperties.class)
|
||||||
|
@ConditionalOnProperty(value = "yexuejc.filter.req.enable", matchIfMissing = false)
|
||||||
public class ParamsRequestBodyAdvice implements RequestBodyAdvice {
|
public class ParamsRequestBodyAdvice implements RequestBodyAdvice {
|
||||||
|
|
||||||
private final RsaProperties properties;
|
private final RsaProperties properties;
|
||||||
@ -49,12 +51,25 @@ public class ParamsRequestBodyAdvice implements RequestBodyAdvice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
|
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<?
|
||||||
|
extends HttpMessageConverter<?>> converterType) {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用入参加密
|
||||||
|
* 自定义入参的解密方式只需要重写 beforeBodyRead 方法即可
|
||||||
|
*
|
||||||
|
* @param inputMessage
|
||||||
|
* @param parameter
|
||||||
|
* @param targetType
|
||||||
|
* @param converterType
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException {
|
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<?
|
||||||
|
extends HttpMessageConverter<?>> converterType) throws IOException {
|
||||||
if (properties.isDecrypt()) {
|
if (properties.isDecrypt()) {
|
||||||
ParamsPO paramsPO = JsonUtil.json2Obj(IOUtils.toString(inputMessage.getBody(), "UTF-8"), ParamsPO.class);
|
ParamsPO paramsPO = JsonUtil.json2Obj(IOUtils.toString(inputMessage.getBody(), "UTF-8"), ParamsPO.class);
|
||||||
//RSA解密
|
//RSA解密
|
||||||
@ -63,7 +78,8 @@ public class ParamsRequestBodyAdvice implements RequestBodyAdvice {
|
|||||||
RSAPrivateKey rsaPrivateKey = null;
|
RSAPrivateKey rsaPrivateKey = null;
|
||||||
if (StrUtil.isEmpty(properties.getPrivateKey())) {
|
if (StrUtil.isEmpty(properties.getPrivateKey())) {
|
||||||
rsaPrivateKey = RSA2.getPrivateKey(
|
rsaPrivateKey = RSA2.getPrivateKey(
|
||||||
this.getClass().getResource(properties.getPrivateKeyPath()).getFile().toString(),
|
// this.getClass().getResource(properties.getPrivateKeyPath()).getFile().toString(),
|
||||||
|
this.getClass().getResourceAsStream(properties.getPrivateKeyPath()),
|
||||||
properties.getPrivateAlias(),
|
properties.getPrivateAlias(),
|
||||||
properties.getPrivatePwd());
|
properties.getPrivatePwd());
|
||||||
} else {
|
} else {
|
||||||
@ -92,7 +108,8 @@ public class ParamsRequestBodyAdvice implements RequestBodyAdvice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
|
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<?
|
||||||
|
extends HttpMessageConverter<?>> converterType) {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import com.yexuejc.base.util.JsonUtil;
|
|||||||
import com.yexuejc.base.util.StrUtil;
|
import com.yexuejc.base.util.StrUtil;
|
||||||
import com.yexuejc.springboot.base.util.LogUtil;
|
import com.yexuejc.springboot.base.util.LogUtil;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -32,6 +33,7 @@ import java.util.Map;
|
|||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
@ConditionalOnClass({ResponseBodyAdvice.class, ServerHttpRequest.class, ServerHttpResponse.class, MediaType.class})
|
@ConditionalOnClass({ResponseBodyAdvice.class, ServerHttpRequest.class, ServerHttpResponse.class, MediaType.class})
|
||||||
@EnableConfigurationProperties(RsaProperties.class)
|
@EnableConfigurationProperties(RsaProperties.class)
|
||||||
|
@ConditionalOnProperty(value = "yexuejc.filter.resp.enable", matchIfMissing = false)
|
||||||
public class ParamsResponseBodyAdvice implements ResponseBodyAdvice {
|
public class ParamsResponseBodyAdvice implements ResponseBodyAdvice {
|
||||||
|
|
||||||
private final RsaProperties properties;
|
private final RsaProperties properties;
|
||||||
@ -47,7 +49,8 @@ public class ParamsResponseBodyAdvice implements ResponseBodyAdvice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
|
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType,
|
||||||
|
ServerHttpRequest request, ServerHttpResponse response) {
|
||||||
if (returnType.getMethod().isAnnotationPresent(SerializedField.class)) {
|
if (returnType.getMethod().isAnnotationPresent(SerializedField.class)) {
|
||||||
//获取注解配置的包含和去除字段
|
//获取注解配置的包含和去除字段
|
||||||
SerializedField serializedField = returnType.getMethodAnnotation(SerializedField.class);
|
SerializedField serializedField = returnType.getMethodAnnotation(SerializedField.class);
|
||||||
@ -74,7 +77,8 @@ public class ParamsResponseBodyAdvice implements ResponseBodyAdvice {
|
|||||||
RSAPrivateKey rsaPrivateKey = null;
|
RSAPrivateKey rsaPrivateKey = null;
|
||||||
if (StrUtil.isEmpty(properties.getPrivateKey())) {
|
if (StrUtil.isEmpty(properties.getPrivateKey())) {
|
||||||
rsaPrivateKey = RSA2.getPrivateKey(
|
rsaPrivateKey = RSA2.getPrivateKey(
|
||||||
this.getClass().getResource(properties.getPrivateKeyPath()).getFile().toString(),
|
// this.getClass().getResource(properties.getPrivateKeyPath()).getFile().toString(),
|
||||||
|
this.getClass().getResourceAsStream(properties.getPrivateKeyPath()),
|
||||||
properties.getPrivateAlias(),
|
properties.getPrivateAlias(),
|
||||||
properties.getPrivatePwd());
|
properties.getPrivatePwd());
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user