diff --git a/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/utils/Desensitizes.java b/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/utils/Desensitizes.java
new file mode 100644
index 00000000..ac093d89
--- /dev/null
+++ b/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/utils/Desensitizes.java
@@ -0,0 +1,84 @@
+package com.orion.ops.framework.common.utils;
+
+import com.orion.lang.utils.Strings;
+
+/**
+ * 脱敏工具类
+ *
+ * // FIXME KIT
+ *
+ * @author Jiahang Li
+ * @version 1.0.0
+ * @since 2019/9/10 9:45
+ */
+public class Desensitizes {
+
+ public static final String REPLACER = "*";
+
+ public static final char REPLACER_CHAR = '*';
+
+ private Desensitizes() {
+ }
+
+ public static String mix(String s, int keepStart, int keepEnd) {
+ return mix(s, keepStart, keepEnd, REPLACER_CHAR);
+ }
+
+ /**
+ * 字符串脱敏
+ * 脱敏后的长度和原先的长度一样
+ *
+ * @param s 原字符
+ * @param keepStart 开始保留长度
+ * @param keepEnd 结束保留长度
+ * @param replacer 脱敏字符
+ * @return 脱敏字符串
+ */
+ public static String mix(String s, int keepStart, int keepEnd, char replacer) {
+ int length = Strings.length(s);
+ if (length == 0) {
+ return Strings.EMPTY;
+ }
+
+ return mix(s, keepStart, keepEnd, Strings.repeat(replacer, length - keepStart - keepEnd), 1);
+ }
+
+ public static String mix(String s, int keepStart, int keepEnd, String replacer) {
+ return mix(s, keepStart, keepEnd, replacer, 1);
+ }
+
+ /**
+ * 字符串脱敏
+ *
+ * @param s 原字符
+ * @param keepStart 开始保留长度
+ * @param keepEnd 结束保留长度
+ * @param replacer 脱敏字符串
+ * @param repeat 脱敏字符串重复次数
+ * @return 脱敏字符串
+ */
+ public static String mix(String s, int keepStart, int keepEnd, String replacer, int repeat) {
+ int length = Strings.length(s);
+ if (length == 0) {
+ return Strings.EMPTY;
+ }
+ if (keepStart < 0) {
+ keepStart = 0;
+ }
+ if (keepEnd < 0) {
+ keepEnd = 0;
+ }
+ // 保留的长度大于等于文本的长度则不脱敏
+ if (keepStart + keepEnd >= length) {
+ return s;
+ }
+ char[] chars = s.toCharArray();
+ char[] replacerArr = Strings.repeat(replacer, repeat).toCharArray();
+ char[] res = new char[keepStart + keepEnd + replacerArr.length];
+ System.arraycopy(chars, 0, res, 0, keepStart);
+ System.arraycopy(replacerArr, 0, res, keepStart, replacerArr.length);
+ System.arraycopy(chars, chars.length - keepEnd, res, keepStart + replacerArr.length, keepEnd);
+ return new String(res);
+ }
+
+}
diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/cache/CacheQuery.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/cache/CacheQuery.java
index af88d70c..c2198c7c 100644
--- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/cache/CacheQuery.java
+++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/cache/CacheQuery.java
@@ -53,7 +53,7 @@ public class CacheQuery {
@SuppressWarnings("unchecked")
public R get(Class c) {
T row = this.get();
- // TODO FIXME mapstruct
+ // TODO mapstruct
return (R) row;
}
diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/config/LogPrinterFieldConfig.java b/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/config/LogPrinterFieldConfig.java
index 38713941..a0dc680d 100644
--- a/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/config/LogPrinterFieldConfig.java
+++ b/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/config/LogPrinterFieldConfig.java
@@ -23,14 +23,14 @@ public class LogPrinterFieldConfig {
/**
* 脱敏的字段
*/
- private List desensitization;
+ private List desensitize;
public void setIgnore(List ignore) {
this.ignore = Utils.parseStringList(ignore);
}
- public void setDesensitization(List desensitization) {
- this.desensitization = Utils.parseStringList(desensitization);
+ public void setDesensitize(List desensitize) {
+ this.desensitize = Utils.parseStringList(desensitize);
}
}
diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/interceptor/BaseLogPrinterInterceptor.java b/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/interceptor/BaseLogPrinterInterceptor.java
index 92935e33..2d671801 100644
--- a/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/interceptor/BaseLogPrinterInterceptor.java
+++ b/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/interceptor/BaseLogPrinterInterceptor.java
@@ -13,6 +13,7 @@ import com.orion.ops.framework.common.annotation.IgnoreLog;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.common.meta.TraceIdHolder;
import com.orion.ops.framework.web.core.config.LogPrinterConfig;
+import com.orion.ops.framework.common.utils.Desensitizes;
import io.swagger.v3.oas.annotations.Operation;
import org.aopalliance.intercept.MethodInvocation;
@@ -74,17 +75,14 @@ public abstract class BaseLogPrinterInterceptor implements LogPrinterInterceptor
// 忽略字段过滤器
PropertyFilter ignoreFilter = (Object object, String name, Object value) -> !config.getField().getIgnore().contains(name);
// 脱敏字段过滤器
- ValueFilter desensitizationFilter = (Object object, String name, Object value) -> {
- if (config.getField().getDesensitization().contains(name)) {
- String s = Objects1.toString(value);
- // Safes.mix()
- // TODO
- return "xxxxxx";
+ ValueFilter desensitizeFilter = (Object object, String name, Object value) -> {
+ if (config.getField().getDesensitize().contains(name)) {
+ return Desensitizes.mix(Objects1.toString(value), 1, 1);
} else {
return value;
}
};
- this.fieldFilter = new SerializeFilter[]{ignoreFilter, desensitizationFilter};
+ this.fieldFilter = new SerializeFilter[]{ignoreFilter, desensitizeFilter};
}
@Override
diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/resources/META-INF/spring-configuration-metadata.json b/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/resources/META-INF/spring-configuration-metadata.json
index ad804169..44801ad0 100644
--- a/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/resources/META-INF/spring-configuration-metadata.json
+++ b/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/resources/META-INF/spring-configuration-metadata.json
@@ -29,7 +29,7 @@
"description": "忽略打印的字段."
},
{
- "name": "logging.printer.field.desensitization",
+ "name": "logging.printer.field.desensitize",
"type": "java.util.List",
"description": "需要脱敏的字段."
},
diff --git a/orion-ops-launch/src/main/java/com/orion/ops/launch/controller/BootstrapController.java b/orion-ops-launch/src/main/java/com/orion/ops/launch/controller/BootstrapController.java
index 0bc1c847..0efe1ed3 100644
--- a/orion-ops-launch/src/main/java/com/orion/ops/launch/controller/BootstrapController.java
+++ b/orion-ops-launch/src/main/java/com/orion/ops/launch/controller/BootstrapController.java
@@ -1,6 +1,7 @@
package com.orion.ops.launch.controller;
import com.orion.ops.framework.common.annotation.RestWrapper;
+import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/server/bootstrap")
public class BootstrapController {
+ @Operation(summary = "检测心跳")
@GetMapping("/health")
public String health() {
return "server ok";
diff --git a/orion-ops-launch/src/main/resources/application-prod.yaml b/orion-ops-launch/src/main/resources/application-prod.yaml
index 2394437f..f0b27f9c 100644
--- a/orion-ops-launch/src/main/resources/application-prod.yaml
+++ b/orion-ops-launch/src/main/resources/application-prod.yaml
@@ -32,3 +32,7 @@ springdoc:
knife4j:
enable: false
+
+logging:
+ printer:
+ mode: ROW
diff --git a/orion-ops-launch/src/main/resources/application.yaml b/orion-ops-launch/src/main/resources/application.yaml
index 416cfafe..5d6299c1 100644
--- a/orion-ops-launch/src/main/resources/application.yaml
+++ b/orion-ops-launch/src/main/resources/application.yaml
@@ -118,7 +118,7 @@ logging:
ignore:
- password,newPassword
- metrics
- desensitization:
+ desensitize:
- phone,phoneNumber
- email,sendEmail