From def99a7d69856ea5fab6dd43374e9714a5fff00c Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Thu, 18 Jun 2020 16:57:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/manager/SensitiveWordsManager.java | 29 ++++++++++++++++++- cloud-common-plugin/pom.xml | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cloud-common-plugin-sensitive/src/main/java/com/cm/plugin/manager/SensitiveWordsManager.java b/cloud-common-plugin-sensitive/src/main/java/com/cm/plugin/manager/SensitiveWordsManager.java index cf66514..248434a 100644 --- a/cloud-common-plugin-sensitive/src/main/java/com/cm/plugin/manager/SensitiveWordsManager.java +++ b/cloud-common-plugin-sensitive/src/main/java/com/cm/plugin/manager/SensitiveWordsManager.java @@ -1,5 +1,6 @@ package com.cm.plugin.manager; +import com.hazelcast.util.StringUtil; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -120,7 +121,7 @@ public class SensitiveWordsManager { } /** - * 返回敏感结果,替换成相应字符 + * 返回敏感过滤结果,替换成相应字符 * * @param content * @param replace @@ -146,6 +147,32 @@ public class SensitiveWordsManager { return sensitiveResult.getSensitive(); } + /** + * 返回敏感过滤结果,替换成相应字符 + * + * @param content + * @param replace + * @param sensitiveWords + * @return + */ + public String getSensitiveWordsResultWithReplace(String content, char replace, List sensitiveWords) { + if (StringUtils.isBlank(content)) { + return null; + } + if (sensitiveWords == null || sensitiveWords.isEmpty()) { + return content; + } + String result = content; + for (String sensitiveWord : sensitiveWords) { + StringBuilder replaceSB = new StringBuilder(); + for (int i = 0; i < sensitiveWord.length(); i++) { + replaceSB.append(replace); + } + result = result.replaceAll(sensitiveWord, replaceSB.toString()); + } + return result; + } + private static class SensitiveWordsManagerBuilder { public static SensitiveWordsManager sensitiveWordsManager = new SensitiveWordsManager(); } diff --git a/cloud-common-plugin/pom.xml b/cloud-common-plugin/pom.xml index a06d6a2..cc27400 100644 --- a/cloud-common-plugin/pom.xml +++ b/cloud-common-plugin/pom.xml @@ -22,6 +22,7 @@ it.sauronsoftware jave + 1.0.2