Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe9d107eef | ||
|
|
0094bf2e69 | ||
|
|
c0fb149558 | ||
|
|
eb55969063 |
20
pom.xml
20
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>springboot-parent</name>
|
||||
<description>杭州铁晟科技有限公司基础依赖</description>
|
||||
@@ -57,55 +57,55 @@
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-database</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-login</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-web</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-util</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-platform</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-message</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-encrypt</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-poi</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-ademo</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-database</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-encrypt</artifactId>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.tiesheng.encrypt;
|
||||
|
||||
|
||||
import com.tiesheng.encrypt.config.EncryptRequestBodyAdvice;
|
||||
import com.tiesheng.encrypt.config.DecryptRequestBodyAdvice;
|
||||
import com.tiesheng.encrypt.config.EncryptResponseBodyAdvice;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.lang.annotation.*;
|
||||
@Target({ElementType.TYPE})
|
||||
@Documented
|
||||
@Import({
|
||||
EncryptRequestBodyAdvice.class,
|
||||
DecryptRequestBodyAdvice.class,
|
||||
EncryptResponseBodyAdvice.class,
|
||||
})
|
||||
public @interface EnableEncryptConfig {
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.charset.Charset;
|
||||
* @author hao
|
||||
*/
|
||||
@ControllerAdvice
|
||||
public class EncryptRequestBodyAdvice implements RequestBodyAdvice {
|
||||
public class DecryptRequestBodyAdvice implements RequestBodyAdvice {
|
||||
|
||||
|
||||
@Autowired
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.tiesheng.encrypt.config;
|
||||
|
||||
import cn.hutool.core.annotation.AnnotationUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import com.tiesheng.util.CommonUtil;
|
||||
import com.tiesheng.util.config.EncryptConfig;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -21,7 +20,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
* @author hao
|
||||
*/
|
||||
@ControllerAdvice
|
||||
public class EncryptResponseBodyAdvice implements ResponseBodyAdvice<Object> {
|
||||
public class EncryptResponseBodyAdvice implements ResponseBodyAdvice<ApiResp> {
|
||||
|
||||
@Autowired
|
||||
EncryptConfig encryptConfig;
|
||||
@@ -32,25 +31,19 @@ public class EncryptResponseBodyAdvice implements ResponseBodyAdvice<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends
|
||||
public ApiResp beforeBodyWrite(ApiResp body, MethodParameter returnType, MediaType selectedContentType, Class<? extends
|
||||
HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
|
||||
|
||||
try {
|
||||
|
||||
String content = JSONUtil.toJsonStr(body);
|
||||
String respData = JSONUtil.parseObj(content).getStr("data");
|
||||
|
||||
if (StrUtil.isEmpty(respData)) {
|
||||
// 无需加密
|
||||
Object data = body.getData();
|
||||
if (data == null || !body.successful()) {
|
||||
return body;
|
||||
}
|
||||
|
||||
JSONObject resp = JSONUtil.parseObj(content);
|
||||
resp.set("encrypted", true);
|
||||
if (resp.getInt("code") == 200) {
|
||||
resp.set("data", encryptConfig.encrypt(respData));
|
||||
}
|
||||
return resp;
|
||||
body.setEncrypt(true);
|
||||
body.setData(encryptConfig.encrypt(CommonUtil.writeJsonString(data)));
|
||||
return body;
|
||||
} catch (Exception var17) {
|
||||
LogFactory.get().info("加密数据异常", var17);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-login</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-message</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-platform</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-poi</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-util</artifactId>
|
||||
@@ -25,6 +25,11 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.tiesheng.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializeFilter;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.tiesheng.util.config.desensitize.DesensitizeValueFilter;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommonUtil {
|
||||
|
||||
|
||||
/**
|
||||
* FastJson配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static FastJsonConfig fastJsonConfig() {
|
||||
FastJsonConfig config = new FastJsonConfig();
|
||||
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,
|
||||
SerializerFeature.WriteNullStringAsEmpty,
|
||||
SerializerFeature.WriteEnumUsingName);
|
||||
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
config.setSerializeFilters(new DesensitizeValueFilter());
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 格式化数据
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String writeJsonString(Object value) throws IOException {
|
||||
FastJsonConfig fastJsonConfig = fastJsonConfig();
|
||||
SerializeFilter[] globalFilters = fastJsonConfig.getSerializeFilters();
|
||||
List<SerializeFilter> allFilters = new ArrayList(Arrays.asList(globalFilters));
|
||||
|
||||
ByteArrayOutputStream outnew = new ByteArrayOutputStream();
|
||||
JSON.writeJSONStringWithFastJsonConfig(outnew, fastJsonConfig.getCharset(),
|
||||
value, fastJsonConfig.getSerializeConfig(),
|
||||
allFilters.toArray(new SerializeFilter[allFilters.size()]),
|
||||
fastJsonConfig.getDateFormat(), JSON.DEFAULT_GENERATE_FEATURE,
|
||||
fastJsonConfig.getSerializerFeatures());
|
||||
return outnew.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.tiesheng.core.config.desensitize;
|
||||
package com.tiesheng.util.config.desensitize;
|
||||
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
@@ -129,6 +129,15 @@ public class ApiResp<T> {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否成功
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean successful() {
|
||||
return code == CODE_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-parent</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>springboot-web</artifactId>
|
||||
@@ -72,11 +72,6 @@
|
||||
<artifactId>springboot-poi</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-annotation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.tiesheng.springboot-parent</groupId>
|
||||
<artifactId>springboot-login</artifactId>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.tiesheng.core.config.json;
|
||||
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import com.tiesheng.core.config.desensitize.DesensitizeValueFilter;
|
||||
import com.tiesheng.util.CommonUtil;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -26,15 +24,9 @@ public class FastJsonMessageConverter {
|
||||
*/
|
||||
@Bean
|
||||
public HttpMessageConverters fastJsonHttpMessageConverters() {
|
||||
FastJsonConfig config = new FastJsonConfig();
|
||||
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,
|
||||
SerializerFeature.WriteNullStringAsEmpty,
|
||||
SerializerFeature.WriteEnumUsingName);
|
||||
config.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
config.setSerializeFilters(new DesensitizeValueFilter());
|
||||
|
||||
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
|
||||
fastConverter.setFastJsonConfig(config);
|
||||
fastConverter.setFastJsonConfig(CommonUtil.fastJsonConfig());
|
||||
fastConverter.setDefaultCharset(StandardCharsets.UTF_8);
|
||||
|
||||
List<MediaType> mediaTypes = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user