From 819ba93913d29dbb4448c2ed4cbcfa9d4feb94a2 Mon Sep 17 00:00:00 2001
From: Ayu <14359932+lin-Ayu0v0@user.noreply.gitee.com>
Date: Sat, 30 Nov 2024 22:14:39 +0800
Subject: [PATCH 1/9] [feature] Desensitize sensitive information.
---
hertzbeat-common/pom.xml | 7 +
.../EmailDesensitizationSerializer.java | 44 ++++
.../PhoneDesensitizationSerializer.java | 39 +++
.../controller/NoticeConfigController.java | 7 +-
.../manager/pojo/dto/NoticeReceiverVO.java | 244 ++++++++++++++++++
pom.xml | 7 +
6 files changed, 346 insertions(+), 2 deletions(-)
create mode 100644 hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java
create mode 100644 hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java
create mode 100644 hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java
diff --git a/hertzbeat-common/pom.xml b/hertzbeat-common/pom.xml
index bfa3faa7c28..7420df1b996 100644
--- a/hertzbeat-common/pom.xml
+++ b/hertzbeat-common/pom.xml
@@ -135,12 +135,19 @@
${poi.version}
compile
+
org.apache.poi
poi-ooxml
${poi.version}
compile
+
+
+ cn.hutool
+ hutool-all
+ ${hutool-all.version}
+
diff --git a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java
new file mode 100644
index 00000000000..5483e8c1b1c
--- /dev/null
+++ b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.common.serialize;
+
+import cn.hutool.core.util.StrUtil;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+import java.io.IOException;
+
+/**
+ * @author Ayu
+ * @date 2024-11-30
+ * @Description Email Desensitizing serializer
+ */
+public class EmailDesensitizationSerializer extends JsonSerializer {
+
+ @Override
+ public void serialize(String email, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
+ String emailDesensitization = "";
+ if (StrUtil.isNotBlank(email)) {
+ int index = StrUtil.indexOf(email, '@');
+ emailDesensitization = index <= 1 ? email :
+ StrUtil.replace(email, 1,index,'.');
+ }
+ jsonGenerator.writeString(emailDesensitization);
+ }
+}
\ No newline at end of file
diff --git a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java
new file mode 100644
index 00000000000..08d86e6e73d
--- /dev/null
+++ b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.common.serialize;
+
+import cn.hutool.core.util.DesensitizedUtil;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
+import java.io.IOException;
+
+/**
+ * @author Ayu
+ * @date 2024-11-30
+ * @Description Phone Desensitizing serializer
+ */
+public class PhoneDesensitizationSerializer extends JsonSerializer {
+
+ @Override
+ public void serialize(String phone, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
+ String phoneDesensitization = DesensitizedUtil.mobilePhone(phone);
+ jsonGenerator.writeString(phoneDesensitization);
+ }
+}
diff --git a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/controller/NoticeConfigController.java b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/controller/NoticeConfigController.java
index 241bddaa070..b8428d74e4b 100644
--- a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/controller/NoticeConfigController.java
+++ b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/controller/NoticeConfigController.java
@@ -19,6 +19,8 @@
import static org.apache.hertzbeat.common.constants.CommonConstants.FAIL_CODE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
+
+import cn.hutool.core.bean.BeanUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -29,6 +31,7 @@
import org.apache.hertzbeat.common.entity.manager.NoticeReceiver;
import org.apache.hertzbeat.common.entity.manager.NoticeRule;
import org.apache.hertzbeat.common.entity.manager.NoticeTemplate;
+import org.apache.hertzbeat.manager.pojo.dto.NoticeReceiverVO;
import org.apache.hertzbeat.manager.service.NoticeConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
@@ -82,9 +85,9 @@ public ResponseEntity> deleteNoticeReceiver(
@GetMapping(path = "/receivers")
@Operation(summary = "Get a list of message notification recipients based on query filter items",
description = "Get a list of message notification recipients based on query filter items")
- public ResponseEntity>> getReceivers(
+ public ResponseEntity>> getReceivers(
@Parameter(description = "en: Recipient name,support fuzzy query", example = "tom") @RequestParam(required = false) final String name) {
- return ResponseEntity.ok(Message.success(noticeConfigService.getNoticeReceivers(name)));
+ return ResponseEntity.ok(Message.success(BeanUtil.copyToList(noticeConfigService.getNoticeReceivers(name),NoticeReceiverVO.class)));
}
@PostMapping(path = "/rule")
diff --git a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java
new file mode 100644
index 00000000000..83e6a616767
--- /dev/null
+++ b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java
@@ -0,0 +1,244 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.manager.pojo.dto;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.persistence.Column;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.validation.constraints.Min;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.Size;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.hertzbeat.common.serialize.EmailDesensitizationSerializer;
+import org.apache.hertzbeat.common.serialize.PhoneDesensitizationSerializer;
+import org.springframework.data.annotation.CreatedBy;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedBy;
+import org.springframework.data.annotation.LastModifiedDate;
+
+import java.time.LocalDateTime;
+
+import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY;
+import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_WRITE;
+
+/**
+ * @author Ayu
+ * @date 2024-11-30
+ * @Description NoticeReceiverVO
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+public class NoticeReceiverVO {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Schema(title = "Recipient entity primary key index ID", description = "Recipient entity primary key index ID",
+ example = "87584674384", accessMode = READ_ONLY)
+ private Long id;
+
+ @Schema(title = "Recipient name", description = "Recipient name",
+ example = "tom", accessMode = READ_WRITE)
+ @Size(max = 100)
+ @NotBlank(message = "name can not null")
+ private String name;
+
+ @Schema(title = "Notification information method: 0-SMS 1-Email 2-webhook 3-WeChat Official Account 4-Enterprise WeChat Robot "
+ + "5-DingTalk Robot 6-FeiShu Robot 7-Telegram Bot 8-SlackWebHook 9-Discord Bot 10-Enterprise WeChat app message",
+ description = "Notification information method: "
+ + "0-SMS 1-Email 2-webhook 3-WeChat Official Account "
+ + "4-Enterprise WeChat Robot 5-DingTalk Robot 6-FeiShu Robot "
+ + "7-Telegram Bot 8-SlackWebHook 9-Discord Bot 10-Enterprise "
+ + "WeChat app message",
+ accessMode = READ_WRITE)
+ @Min(0)
+ @NotNull(message = "type can not null")
+ private Byte type;
+
+ @Schema(title = "Mobile number: Valid when the notification method is SMS",
+ description = "Mobile number: Valid when the notification method is SMS",
+ example = "18923435643", accessMode = READ_WRITE)
+ @Size(max = 100)
+ @JsonSerialize(using = PhoneDesensitizationSerializer.class)
+ private String phone;
+
+ @Schema(title = "Email account: Valid when the notification method is email",
+ description = "Email account: Valid when the notification method is email",
+ example = "tom@qq.com", accessMode = READ_WRITE)
+ @Size(max = 100)
+ @JsonSerialize(using = EmailDesensitizationSerializer.class)
+ private String email;
+
+ @Schema(title = "URL address: The notification method is valid for webhook",
+ description = "URL address: The notification method is valid for webhook",
+ example = "https://www.tancloud.cn", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String hookUrl;
+
+ @Schema(title = "openId : The notification method is valid for WeChat official account, enterprise WeChat robot or FlyBook robot",
+ description = "openId : The notification method is valid for WeChat official account, enterprise WeChat robot or FlyBook robot",
+ example = "343432", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String wechatId;
+
+ @Schema(title = "Access token : The notification method is valid for DingTalk robot",
+ description = "Access token : The notification method is valid for DingTalk robot",
+ example = "34823984635647", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String accessToken;
+
+ @Schema(title = "Telegram bot token : The notification method is valid for Telegram Bot",
+ description = "Telegram bot token : The notification method is valid for Telegram Bot",
+ example = "1499012345:AAEOB_wEYS-DZyPM3h5NzI8voJMXXXXXX", accessMode = READ_WRITE)
+ private String tgBotToken;
+
+ @Schema(title = "Telegram user id: The notification method is valid for Telegram Bot",
+ description = "Telegram user id: The notification method is valid for Telegram Bot",
+ example = "779294123", accessMode = READ_WRITE)
+ private String tgUserId;
+
+ @Schema(title = "DingTalk,FeiShu,WeWork user id: The notification method is valid for DingTalk,FeiShu,WeWork Bot",
+ description = "DingTalk,FeiShu,WeWork user id: The notification method is valid for DingTalk,FeiShu,WeWork Bot",
+ example = "779294123", accessMode = READ_WRITE)
+ private String userId;
+
+ @Schema(title = "URL address: The notification method is valid for Slack",
+ description = "URL address: The notification method is valid for Slack",
+ example = "https://hooks.slack.com/services/XXXX/XXXX/XXXX", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String slackWebHookUrl;
+
+ @Schema(title = "Enterprise weChat message: The notification method is valid for Enterprise WeChat app message",
+ description = "Enterprise weChat message: The notification method is valid for Enterprise WeChat app message",
+ example = "ww1a603432123d0dc1", accessMode = READ_WRITE)
+ private String corpId;
+
+ @Schema(title = "Enterprise weChat appId: The notification method is valid for Enterprise WeChat app message",
+ description = "Enterprise weChat appId: The notification method is valid for Enterprise WeChat app message",
+ example = "1000001", accessMode = READ_WRITE)
+ private Integer agentId;
+
+ @Schema(title = "Enterprise weChat secret: The notification method is valid for Enterprise WeChat app message",
+ description = "Enterprise weChat secret: The notification method is valid for Enterprise WeChat app message",
+ example = "oUydwn92ey0lnuY02MixNa57eNK-20dJn5NEOG-u2uE", accessMode = READ_WRITE)
+ private String appSecret;
+
+ @Schema(title = "Enterprise weChat party id: The notification method is valid for Enterprise WeChat app message",
+ description = "Enterprise weChat party id: The notification method is valid for Enterprise WeChat app message",
+ example = "779294123", accessMode = READ_WRITE)
+ private String partyId;
+
+ @Schema(title = "Enterprise weChat tag id: The notification method is valid for Enterprise WeChat app message",
+ description = "Enterprise weChat tag id: The notification method is valid for Enterprise WeChat app message",
+ example = "779294123", accessMode = READ_WRITE)
+ private String tagId;
+
+ @Schema(title = "Discord channel id: The notification method is valid for Discord",
+ description = "Discord channel id: The notification method is valid for Discord",
+ example = "1065303416030642266", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String discordChannelId;
+
+ @Schema(title = "Discord bot token: The notification method is valid for Discord",
+ description = "Discord bot token: The notification method is valid for Discord",
+ example = "MTA2NTMwMzU0ODY4Mzg4MjUzNw.xxxxx.xxxxxxx", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String discordBotToken;
+
+ @Schema(title = "huawei cloud SMN ak: If the notification method is valid for huawei cloud SMN",
+ description = "huawei cloud SMN ak: If the notification method is valid for huawei cloud SMN",
+ example = "NCVBODJOEYHSW3VNXXXX", accessMode = READ_WRITE)
+ @Size(max = 22)
+ @Column(length = 22)
+ private String smnAk;
+
+ @Schema(title = "huawei cloud SMN sk: If the notification method is valid for huawei cloud SMN",
+ description = "huawei cloud SMN sk: If the notification method is valid for huawei cloud SMN",
+ example = "nmSNhUJN9MlpPl8lfCsgdA0KvHCL9JXXXX", accessMode = READ_WRITE)
+ @Size(max = 42)
+ @Column(length = 42)
+ private String smnSk;
+
+ @Schema(title = "huawei cloud SMN projectId: If the notification method is valid for huawei cloud SMN",
+ description = "huawei cloud SMN projectId: If the notification method is valid for huawei cloud SMN",
+ example = "320c2fb11edb47a481c299c1XXXXXX", accessMode = READ_WRITE)
+ @Size(max = 32)
+ @Column(length = 32)
+ private String smnProjectId;
+
+ @Schema(title = "huawei cloud SMN region: If the notification method is valid for huawei cloud SMN",
+ description = "huawei cloud SMN region: If the notification method is valid for huawei cloud SMN",
+ example = "cn-east-3", accessMode = READ_WRITE)
+ @Size(max = 32)
+ @Column(length = 32)
+ private String smnRegion;
+
+ @Schema(title = "huawei cloud SMN TopicUrn: If the notification method is valid for huawei cloud SMN",
+ description = "huawei cloud SMN TopicUrn: If the notification method is valid for huawei cloud SMN",
+ example = "urn:smn:cn-east-3:xxx:hertzbeat_test", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String smnTopicUrn;
+
+ @Schema(title = "serverChanToken : The notification method is valid for ServerChan",
+ description = "serverChanToken : The notification method is valid for ServerChan",
+ example = "SCT193569TSNm6xIabdjqeZPtOGOWcvU1e", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String serverChanToken;
+
+ @Schema(title = "Gotify token : The notification method is valid for Gotify",
+ description = "Gotify token : The notification method is valid for Gotify",
+ example = "A845h__ZMqDxZlO", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String gotifyToken;
+
+ @Schema(title = "The creator of this record", example = "tom",
+ accessMode = READ_ONLY)
+ @CreatedBy
+ private String creator;
+
+ @Schema(title = "This record was last modified by", example = "tom", accessMode = READ_ONLY)
+ @LastModifiedBy
+ private String modifier;
+
+ @Schema(title = "Record creation time (millisecond timestamp)",
+ example = "1612198922000", accessMode = READ_ONLY)
+ @CreatedDate
+ private LocalDateTime gmtCreate;
+
+ @Schema(title = "Record the latest modification time (timestamp in milliseconds)",
+ example = "1612198444000", accessMode = READ_ONLY)
+ @LastModifiedDate
+ private LocalDateTime gmtUpdate;
+}
diff --git a/pom.xml b/pom.xml
index 05974f113fa..bdb98ab1177 100644
--- a/pom.xml
+++ b/pom.xml
@@ -163,6 +163,7 @@
3.1.37
3.23.5
3.8.0
+ 5.8.20
0.13.3
2.23
@@ -453,6 +454,12 @@
netty-all
${netty.version}
+
+
+ cn.hutool
+ hutool-all
+ ${hutool-all.version}
+
From 278afe7e9ec899f594c1505ef8245832eadc9b15 Mon Sep 17 00:00:00 2001
From: Ayu <127600988+ayu-v0@users.noreply.github.com>
Date: Sun, 1 Dec 2024 21:05:37 +0800
Subject: [PATCH 2/9] Update EmailDesensitizationSerializer.java
Signed-off-by: Ayu <127600988+ayu-v0@users.noreply.github.com>
---
.../common/serialize/EmailDesensitizationSerializer.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java
index 5483e8c1b1c..399da76e8a2 100644
--- a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java
+++ b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java
@@ -25,7 +25,6 @@
import java.io.IOException;
/**
- * @author Ayu
* @date 2024-11-30
* @Description Email Desensitizing serializer
*/
@@ -41,4 +40,4 @@ public void serialize(String email, JsonGenerator jsonGenerator, SerializerProvi
}
jsonGenerator.writeString(emailDesensitization);
}
-}
\ No newline at end of file
+}
From f00f3c875a3a7cbdb6d432d74872e5c8780c02b3 Mon Sep 17 00:00:00 2001
From: Ayu <127600988+ayu-v0@users.noreply.github.com>
Date: Sun, 1 Dec 2024 21:06:19 +0800
Subject: [PATCH 3/9] Update NoticeReceiverVO.java
Signed-off-by: Ayu <127600988+ayu-v0@users.noreply.github.com>
---
.../org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java
index 83e6a616767..d731a927018 100644
--- a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java
+++ b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java
@@ -44,7 +44,6 @@
import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_WRITE;
/**
- * @author Ayu
* @date 2024-11-30
* @Description NoticeReceiverVO
*/
From 316e301af522d5d107f096ece0d90682e3b7f72b Mon Sep 17 00:00:00 2001
From: Ayu <127600988+ayu-v0@users.noreply.github.com>
Date: Sun, 1 Dec 2024 21:13:46 +0800
Subject: [PATCH 4/9] Update PhoneDesensitizationSerializer.java
Signed-off-by: Ayu <127600988+ayu-v0@users.noreply.github.com>
---
.../common/serialize/PhoneDesensitizationSerializer.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java
index 08d86e6e73d..e22a88faba9 100644
--- a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java
+++ b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java
@@ -25,7 +25,6 @@
import java.io.IOException;
/**
- * @author Ayu
* @date 2024-11-30
* @Description Phone Desensitizing serializer
*/
From 1b15a97699e456590dd064bd93337b5741d3a48e Mon Sep 17 00:00:00 2001
From: Ayu <127600988+ayu-v0@users.noreply.github.com>
Date: Wed, 4 Dec 2024 22:12:21 +0800
Subject: [PATCH 5/9] Update EmailDesensitizationSerializer.java
Signed-off-by: Ayu <127600988+ayu-v0@users.noreply.github.com>
---
.../common/serialize/EmailDesensitizationSerializer.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java
index 399da76e8a2..8a0c32eb2a7 100644
--- a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java
+++ b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java
@@ -25,8 +25,8 @@
import java.io.IOException;
/**
- * @date 2024-11-30
- * @Description Email Desensitizing serializer
+ * 2024-11-30
+ * Email Desensitizing serializer
*/
public class EmailDesensitizationSerializer extends JsonSerializer {
From 14599d3be6e810db6178a88f403648b543123997 Mon Sep 17 00:00:00 2001
From: Ayu <127600988+ayu-v0@users.noreply.github.com>
Date: Wed, 4 Dec 2024 22:12:56 +0800
Subject: [PATCH 6/9] Update PhoneDesensitizationSerializer.java
Signed-off-by: Ayu <127600988+ayu-v0@users.noreply.github.com>
---
.../common/serialize/PhoneDesensitizationSerializer.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java
index e22a88faba9..ea021916a6c 100644
--- a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java
+++ b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java
@@ -25,8 +25,8 @@
import java.io.IOException;
/**
- * @date 2024-11-30
- * @Description Phone Desensitizing serializer
+ * 2024-11-30
+ * Phone Desensitizing serializer
*/
public class PhoneDesensitizationSerializer extends JsonSerializer {
From 4ad9bcea27ec63c88bd8656e198fb2d885f5b991 Mon Sep 17 00:00:00 2001
From: Ayu <127600988+ayu-v0@users.noreply.github.com>
Date: Wed, 4 Dec 2024 22:13:38 +0800
Subject: [PATCH 7/9] Update NoticeReceiverVO.java
Signed-off-by: Ayu <127600988+ayu-v0@users.noreply.github.com>
---
.../apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java
index d731a927018..f909c05d5ac 100644
--- a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java
+++ b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java
@@ -44,8 +44,8 @@
import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_WRITE;
/**
- * @date 2024-11-30
- * @Description NoticeReceiverVO
+ * 2024-11-30
+ * NoticeReceiverVO
*/
@Data
@AllArgsConstructor
From 2b61222ad8917504edb021d62c5114c92bb76940 Mon Sep 17 00:00:00 2001
From: Ayu <127600988+ayu-v0@users.noreply.github.com>
Date: Wed, 4 Dec 2024 22:21:10 +0800
Subject: [PATCH 8/9] Update NoticeReceiverVO.java
Signed-off-by: Ayu <127600988+ayu-v0@users.noreply.github.com>
---
.../org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java
index f909c05d5ac..cc31ae0ad9c 100644
--- a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java
+++ b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/NoticeReceiverVO.java
@@ -45,7 +45,6 @@
/**
* 2024-11-30
- * NoticeReceiverVO
*/
@Data
@AllArgsConstructor
From 17e9797866c1bd0b36cab9b6faa7341e1d7f51b0 Mon Sep 17 00:00:00 2001
From: Ayu <14359932+lin-Ayu0v0@user.noreply.gitee.com>
Date: Fri, 6 Dec 2024 10:21:37 +0800
Subject: [PATCH 9/9] [feature] Desensitize sensitive information
---
.../hertzbeat/common/cache/CacheFactory.java | 17 +-
.../common/entity/dto/NoticeReceiverVO.java | 243 ++++++++++++++++++
.../EmailDesensitizationSerializer.java | 14 +-
.../PhoneDesensitizationSerializer.java | 18 +-
.../controller/NoticeConfigController.java | 2 +-
.../service/impl/NoticeConfigServiceImpl.java | 18 ++
6 files changed, 299 insertions(+), 13 deletions(-)
create mode 100644 hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/dto/NoticeReceiverVO.java
diff --git a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/cache/CacheFactory.java b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/cache/CacheFactory.java
index 37aaf0703c6..921eee1667f 100644
--- a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/cache/CacheFactory.java
+++ b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/cache/CacheFactory.java
@@ -27,13 +27,16 @@ private CacheFactory() {}
private static final CommonCacheService NOTICE_CACHE =
new CaffeineCacheServiceImpl<>(10, 1000, Duration.ofDays(1), false);
-
+
private static final CommonCacheService ALERT_SILENCE_CACHE =
new CaffeineCacheServiceImpl<>(10, 1000, Duration.ofDays(1), false);
-
+
private static final CommonCacheService ALERT_CONVERGE_CACHE =
new CaffeineCacheServiceImpl<>(10, 1000, Duration.ofDays(1), false);
-
+
+ private static final CommonCacheService DESENSITIZATION_MAP_CACHE =
+ new CaffeineCacheServiceImpl<>(10, 1000, Duration.ofDays(1), false);
+
/**
* get notice cache
* @return caffeine cache
@@ -41,7 +44,7 @@ private CacheFactory() {}
public static CommonCacheService getNoticeCache() {
return NOTICE_CACHE;
}
-
+
/**
* get alert silence cache
* @return caffeine cache
@@ -57,4 +60,10 @@ public static CommonCacheService getAlertSilenceCache() {
public static CommonCacheService getAlertConvergeCache() {
return ALERT_CONVERGE_CACHE;
}
+
+ /**
+ * get desensitizationMap cache
+ * @return desensitizationMap cache
+ */
+ public static CommonCacheService getDesensitizationMapCache(){return DESENSITIZATION_MAP_CACHE;};
}
diff --git a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/dto/NoticeReceiverVO.java b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/dto/NoticeReceiverVO.java
new file mode 100644
index 00000000000..92e4ffe364d
--- /dev/null
+++ b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/dto/NoticeReceiverVO.java
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.common.entity.dto;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.persistence.Column;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.validation.constraints.Min;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.Size;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.hertzbeat.common.serialize.EmailDesensitizationSerializer;
+import org.apache.hertzbeat.common.serialize.PhoneDesensitizationSerializer;
+import org.springframework.data.annotation.CreatedBy;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedBy;
+import org.springframework.data.annotation.LastModifiedDate;
+
+import java.time.LocalDateTime;
+
+import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY;
+import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_WRITE;
+
+/**
+ * Ayu
+ * 2024-12-06
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+public class NoticeReceiverVO {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Schema(title = "Recipient entity primary key index ID", description = "Recipient entity primary key index ID",
+ example = "87584674384", accessMode = READ_ONLY)
+ private Long id;
+
+ @Schema(title = "Recipient name", description = "Recipient name",
+ example = "tom", accessMode = READ_WRITE)
+ @Size(max = 100)
+ @NotBlank(message = "name can not null")
+ private String name;
+
+ @Schema(title = "Notification information method: 0-SMS 1-Email 2-webhook 3-WeChat Official Account 4-Enterprise WeChat Robot "
+ + "5-DingTalk Robot 6-FeiShu Robot 7-Telegram Bot 8-SlackWebHook 9-Discord Bot 10-Enterprise WeChat app message",
+ description = "Notification information method: "
+ + "0-SMS 1-Email 2-webhook 3-WeChat Official Account "
+ + "4-Enterprise WeChat Robot 5-DingTalk Robot 6-FeiShu Robot "
+ + "7-Telegram Bot 8-SlackWebHook 9-Discord Bot 10-Enterprise "
+ + "WeChat app message",
+ accessMode = READ_WRITE)
+ @Min(0)
+ @NotNull(message = "type can not null")
+ private Byte type;
+
+ @Schema(title = "Mobile number: Valid when the notification method is SMS",
+ description = "Mobile number: Valid when the notification method is SMS",
+ example = "18923435643", accessMode = READ_WRITE)
+ @Size(max = 100)
+ @JsonSerialize(using = PhoneDesensitizationSerializer.class)
+ private String phone;
+
+ @Schema(title = "Email account: Valid when the notification method is email",
+ description = "Email account: Valid when the notification method is email",
+ example = "tom@qq.com", accessMode = READ_WRITE)
+ @Size(max = 100)
+ @JsonSerialize(using = EmailDesensitizationSerializer.class)
+ private String email;
+
+ @Schema(title = "URL address: The notification method is valid for webhook",
+ description = "URL address: The notification method is valid for webhook",
+ example = "https://www.tancloud.cn", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String hookUrl;
+
+ @Schema(title = "openId : The notification method is valid for WeChat official account, enterprise WeChat robot or FlyBook robot",
+ description = "openId : The notification method is valid for WeChat official account, enterprise WeChat robot or FlyBook robot",
+ example = "343432", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String wechatId;
+
+ @Schema(title = "Access token : The notification method is valid for DingTalk robot",
+ description = "Access token : The notification method is valid for DingTalk robot",
+ example = "34823984635647", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String accessToken;
+
+ @Schema(title = "Telegram bot token : The notification method is valid for Telegram Bot",
+ description = "Telegram bot token : The notification method is valid for Telegram Bot",
+ example = "1499012345:AAEOB_wEYS-DZyPM3h5NzI8voJMXXXXXX", accessMode = READ_WRITE)
+ private String tgBotToken;
+
+ @Schema(title = "Telegram user id: The notification method is valid for Telegram Bot",
+ description = "Telegram user id: The notification method is valid for Telegram Bot",
+ example = "779294123", accessMode = READ_WRITE)
+ private String tgUserId;
+
+ @Schema(title = "DingTalk,FeiShu,WeWork user id: The notification method is valid for DingTalk,FeiShu,WeWork Bot",
+ description = "DingTalk,FeiShu,WeWork user id: The notification method is valid for DingTalk,FeiShu,WeWork Bot",
+ example = "779294123", accessMode = READ_WRITE)
+ private String userId;
+
+ @Schema(title = "URL address: The notification method is valid for Slack",
+ description = "URL address: The notification method is valid for Slack",
+ example = "https://hooks.slack.com/services/XXXX/XXXX/XXXX", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String slackWebHookUrl;
+
+ @Schema(title = "Enterprise weChat message: The notification method is valid for Enterprise WeChat app message",
+ description = "Enterprise weChat message: The notification method is valid for Enterprise WeChat app message",
+ example = "ww1a603432123d0dc1", accessMode = READ_WRITE)
+ private String corpId;
+
+ @Schema(title = "Enterprise weChat appId: The notification method is valid for Enterprise WeChat app message",
+ description = "Enterprise weChat appId: The notification method is valid for Enterprise WeChat app message",
+ example = "1000001", accessMode = READ_WRITE)
+ private Integer agentId;
+
+ @Schema(title = "Enterprise weChat secret: The notification method is valid for Enterprise WeChat app message",
+ description = "Enterprise weChat secret: The notification method is valid for Enterprise WeChat app message",
+ example = "oUydwn92ey0lnuY02MixNa57eNK-20dJn5NEOG-u2uE", accessMode = READ_WRITE)
+ private String appSecret;
+
+ @Schema(title = "Enterprise weChat party id: The notification method is valid for Enterprise WeChat app message",
+ description = "Enterprise weChat party id: The notification method is valid for Enterprise WeChat app message",
+ example = "779294123", accessMode = READ_WRITE)
+ private String partyId;
+
+ @Schema(title = "Enterprise weChat tag id: The notification method is valid for Enterprise WeChat app message",
+ description = "Enterprise weChat tag id: The notification method is valid for Enterprise WeChat app message",
+ example = "779294123", accessMode = READ_WRITE)
+ private String tagId;
+
+ @Schema(title = "Discord channel id: The notification method is valid for Discord",
+ description = "Discord channel id: The notification method is valid for Discord",
+ example = "1065303416030642266", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String discordChannelId;
+
+ @Schema(title = "Discord bot token: The notification method is valid for Discord",
+ description = "Discord bot token: The notification method is valid for Discord",
+ example = "MTA2NTMwMzU0ODY4Mzg4MjUzNw.xxxxx.xxxxxxx", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String discordBotToken;
+
+ @Schema(title = "huawei cloud SMN ak: If the notification method is valid for huawei cloud SMN",
+ description = "huawei cloud SMN ak: If the notification method is valid for huawei cloud SMN",
+ example = "NCVBODJOEYHSW3VNXXXX", accessMode = READ_WRITE)
+ @Size(max = 22)
+ @Column(length = 22)
+ private String smnAk;
+
+ @Schema(title = "huawei cloud SMN sk: If the notification method is valid for huawei cloud SMN",
+ description = "huawei cloud SMN sk: If the notification method is valid for huawei cloud SMN",
+ example = "nmSNhUJN9MlpPl8lfCsgdA0KvHCL9JXXXX", accessMode = READ_WRITE)
+ @Size(max = 42)
+ @Column(length = 42)
+ private String smnSk;
+
+ @Schema(title = "huawei cloud SMN projectId: If the notification method is valid for huawei cloud SMN",
+ description = "huawei cloud SMN projectId: If the notification method is valid for huawei cloud SMN",
+ example = "320c2fb11edb47a481c299c1XXXXXX", accessMode = READ_WRITE)
+ @Size(max = 32)
+ @Column(length = 32)
+ private String smnProjectId;
+
+ @Schema(title = "huawei cloud SMN region: If the notification method is valid for huawei cloud SMN",
+ description = "huawei cloud SMN region: If the notification method is valid for huawei cloud SMN",
+ example = "cn-east-3", accessMode = READ_WRITE)
+ @Size(max = 32)
+ @Column(length = 32)
+ private String smnRegion;
+
+ @Schema(title = "huawei cloud SMN TopicUrn: If the notification method is valid for huawei cloud SMN",
+ description = "huawei cloud SMN TopicUrn: If the notification method is valid for huawei cloud SMN",
+ example = "urn:smn:cn-east-3:xxx:hertzbeat_test", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String smnTopicUrn;
+
+ @Schema(title = "serverChanToken : The notification method is valid for ServerChan",
+ description = "serverChanToken : The notification method is valid for ServerChan",
+ example = "SCT193569TSNm6xIabdjqeZPtOGOWcvU1e", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String serverChanToken;
+
+ @Schema(title = "Gotify token : The notification method is valid for Gotify",
+ description = "Gotify token : The notification method is valid for Gotify",
+ example = "A845h__ZMqDxZlO", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String gotifyToken;
+
+ @Schema(title = "The creator of this record", example = "tom",
+ accessMode = READ_ONLY)
+ @CreatedBy
+ private String creator;
+
+ @Schema(title = "This record was last modified by", example = "tom", accessMode = READ_ONLY)
+ @LastModifiedBy
+ private String modifier;
+
+ @Schema(title = "Record creation time (millisecond timestamp)",
+ example = "1612198922000", accessMode = READ_ONLY)
+ @CreatedDate
+ private LocalDateTime gmtCreate;
+
+ @Schema(title = "Record the latest modification time (timestamp in milliseconds)",
+ example = "1612198444000", accessMode = READ_ONLY)
+ @LastModifiedDate
+ private LocalDateTime gmtUpdate;
+}
diff --git a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java
index 5483e8c1b1c..db3cb534dc2 100644
--- a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java
+++ b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/EmailDesensitizationSerializer.java
@@ -21,23 +21,29 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
+import org.apache.hertzbeat.common.cache.CacheFactory;
+import org.apache.hertzbeat.common.cache.CommonCacheService;
+import org.apache.hertzbeat.common.entity.dto.NoticeReceiverVO;
import java.io.IOException;
/**
- * @author Ayu
- * @date 2024-11-30
- * @Description Email Desensitizing serializer
+ * 2024-12-06
+ * Email Desensitizing serializer
*/
public class EmailDesensitizationSerializer extends JsonSerializer {
@Override
public void serialize(String email, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
String emailDesensitization = "";
+ CommonCacheService desensitizationMapCache = CacheFactory.getDesensitizationMapCache();
if (StrUtil.isNotBlank(email)) {
int index = StrUtil.indexOf(email, '@');
emailDesensitization = index <= 1 ? email :
- StrUtil.replace(email, 1,index,'.');
+ StrUtil.replace(email, 1,index,'*');
+ NoticeReceiverVO currentValue = (NoticeReceiverVO)jsonGenerator.getOutputContext().getCurrentValue();
+
+ desensitizationMapCache.put(currentValue.getId()+"_"+emailDesensitization, email);
}
jsonGenerator.writeString(emailDesensitization);
}
diff --git a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java
index 08d86e6e73d..32a96eef248 100644
--- a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java
+++ b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/serialize/PhoneDesensitizationSerializer.java
@@ -18,22 +18,32 @@
package org.apache.hertzbeat.common.serialize;
import cn.hutool.core.util.DesensitizedUtil;
+import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
+import org.apache.hertzbeat.common.cache.CacheFactory;
+import org.apache.hertzbeat.common.cache.CommonCacheService;
+import org.apache.hertzbeat.common.entity.dto.NoticeReceiverVO;
import java.io.IOException;
/**
- * @author Ayu
- * @date 2024-11-30
- * @Description Phone Desensitizing serializer
+ * 2024-12-06
+ * Phone Desensitizing serializer
*/
public class PhoneDesensitizationSerializer extends JsonSerializer {
@Override
public void serialize(String phone, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
- String phoneDesensitization = DesensitizedUtil.mobilePhone(phone);
+ String phoneDesensitization = "";
+ CommonCacheService desensitizationMapCache = CacheFactory.getDesensitizationMapCache();
+ if (StrUtil.isNotBlank(phone)){
+ phoneDesensitization = DesensitizedUtil.mobilePhone(phone);
+ NoticeReceiverVO currentValue = (NoticeReceiverVO)jsonGenerator.getOutputContext().getCurrentValue();
+ desensitizationMapCache.put(currentValue.getId()+"_"+phoneDesensitization, phone);
+ }
+
jsonGenerator.writeString(phoneDesensitization);
}
}
diff --git a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/controller/NoticeConfigController.java b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/controller/NoticeConfigController.java
index b8428d74e4b..f998383cd84 100644
--- a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/controller/NoticeConfigController.java
+++ b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/controller/NoticeConfigController.java
@@ -28,10 +28,10 @@
import java.util.Optional;
import javax.validation.Valid;
import org.apache.hertzbeat.common.entity.dto.Message;
+import org.apache.hertzbeat.common.entity.dto.NoticeReceiverVO;
import org.apache.hertzbeat.common.entity.manager.NoticeReceiver;
import org.apache.hertzbeat.common.entity.manager.NoticeRule;
import org.apache.hertzbeat.common.entity.manager.NoticeTemplate;
-import org.apache.hertzbeat.manager.pojo.dto.NoticeReceiverVO;
import org.apache.hertzbeat.manager.service.NoticeConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
diff --git a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/service/impl/NoticeConfigServiceImpl.java b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/service/impl/NoticeConfigServiceImpl.java
index b4dd9b5c01d..65142b80bbe 100644
--- a/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/service/impl/NoticeConfigServiceImpl.java
+++ b/hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/service/impl/NoticeConfigServiceImpl.java
@@ -17,6 +17,7 @@
package org.apache.hertzbeat.manager.service.impl;
+import cn.hutool.core.util.ObjectUtil;
import jakarta.persistence.criteria.Predicate;
import java.io.IOException;
import java.io.InputStream;
@@ -132,6 +133,13 @@ public void addReceiver(NoticeReceiver noticeReceiver) {
@Override
public void editReceiver(NoticeReceiver noticeReceiver) {
+ CommonCacheService desensitizationMapCache = CacheFactory.getDesensitizationMapCache();
+ if (ObjectUtil.isNotEmpty(noticeReceiver.getEmail()) && ObjectUtil.isNotEmpty(desensitizationMapCache.get(noticeReceiver.getId()+"_"+noticeReceiver.getEmail()))){
+ noticeReceiver.setEmail((String) desensitizationMapCache.get(noticeReceiver.getId()+"_"+noticeReceiver.getEmail()));
+ }
+ if (ObjectUtil.isNotEmpty(noticeReceiver.getPhone()) && ObjectUtil.isNotEmpty(desensitizationMapCache.get(noticeReceiver.getId()+"_"+noticeReceiver.getPhone()))){
+ noticeReceiver.setPhone((String) desensitizationMapCache.get(noticeReceiver.getId()+"_"+noticeReceiver.getPhone()));
+ }
noticeReceiverDao.save(noticeReceiver);
}
@@ -267,6 +275,16 @@ public NoticeTemplate getDefaultNoticeTemplateByType(Byte type) {
@Override
public boolean sendTestMsg(NoticeReceiver noticeReceiver) {
+ if (null != noticeReceiver.getId()){
+ CommonCacheService desensitizationMapCache = CacheFactory.getDesensitizationMapCache();
+ if (ObjectUtil.isNotEmpty(noticeReceiver.getEmail()) && ObjectUtil.isNotEmpty(desensitizationMapCache.get(noticeReceiver.getId()+"_"+noticeReceiver.getEmail()))){
+ noticeReceiver.setEmail((String) desensitizationMapCache.get(noticeReceiver.getId()+"_"+noticeReceiver.getEmail()));
+ }
+ if (ObjectUtil.isNotEmpty(noticeReceiver.getPhone()) && ObjectUtil.isNotEmpty(desensitizationMapCache.get(noticeReceiver.getId()+"_"+noticeReceiver.getPhone()))){
+ noticeReceiver.setPhone((String) desensitizationMapCache.get(noticeReceiver.getId()+"_"+noticeReceiver.getPhone()));
+ }
+ }
+
Map tags = new HashMap<>(8);
tags.put(CommonConstants.TAG_MONITOR_ID, "100");
tags.put(CommonConstants.TAG_MONITOR_NAME, "100Name");