@@ -255,6 +286,13 @@ public class SensitiveWordBs implements ISensitiveWordDestroy {
context.enableWordCheck(enableWordCheck);
context.enableIpv4Check(enableIpv4Check);
+ // 校验策略实现配置
+ context.wordCheckWord(wordCheckWord);
+ context.wordCheckEmail(wordCheckEmail);
+ context.wordCheckNum(wordCheckNum);
+ context.wordCheckUrl(wordCheckUrl);
+ context.wordCheckIpv4(wordCheckIpv4);
+
// 额外配置
context.sensitiveCheckNumLen(numCheckLen);
context.wordReplace(wordReplace);
@@ -370,6 +408,41 @@ public class SensitiveWordBs implements ISensitiveWordDestroy {
return this;
}
+ public SensitiveWordBs wordCheckWord(IWordCheck wordCheckWord) {
+ ArgUtil.notNull(wordCheckWord, "wordCheckWord");
+
+ this.wordCheckWord = wordCheckWord;
+ return this;
+ }
+
+ public SensitiveWordBs wordCheckNum(IWordCheck wordCheckNum) {
+ ArgUtil.notNull(wordCheckNum, "wordCheckNum");
+
+ this.wordCheckNum = wordCheckNum;
+ return this;
+ }
+
+ public SensitiveWordBs wordCheckEmail(IWordCheck wordCheckEmail) {
+ ArgUtil.notNull(wordCheckEmail, "wordCheckEmail");
+
+ this.wordCheckEmail = wordCheckEmail;
+ return this;
+ }
+
+ public SensitiveWordBs wordCheckUrl(IWordCheck wordCheckUrl) {
+ ArgUtil.notNull(wordCheckUrl, "wordCheckUrl");
+
+ this.wordCheckUrl = wordCheckUrl;
+ return this;
+ }
+
+ public SensitiveWordBs wordCheckIpv4(IWordCheck wordCheckIpv4) {
+ ArgUtil.notNull(wordCheckIpv4, "wordCheckIpv4");
+
+ this.wordCheckIpv4 = wordCheckIpv4;
+ return this;
+ }
+
//-------------------------------------------------------- 基础属性设置
/**
* 是否启用 ipv4 校验
diff --git a/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordContext.java b/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordContext.java
index 30663e3..bcd884c 100644
--- a/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordContext.java
+++ b/src/main/java/com/github/houbb/sensitive/word/bs/SensitiveWordContext.java
@@ -1,6 +1,7 @@
package com.github.houbb.sensitive.word.bs;
import com.github.houbb.sensitive.word.api.*;
+import com.github.houbb.sensitive.word.support.check.WordChecks;
/**
* 上下文
@@ -133,6 +134,36 @@ public class SensitiveWordContext implements IWordContext {
*/
private IWordResultCondition wordResultCondition;
+ /**
+ * 单词检测策略
+ * @since 0.25.0
+ */
+ private IWordCheck wordCheckWord;
+
+ /**
+ * 数字检测策略
+ * @since 0.25.0
+ */
+ private IWordCheck wordCheckNum;
+
+ /**
+ * email 检测策略
+ * @since 0.25.0
+ */
+ private IWordCheck wordCheckEmail;
+
+ /**
+ * URL 检测策略
+ * @since 0.25.0
+ */
+ private IWordCheck wordCheckUrl;
+
+ /**
+ * ipv4 检测策略
+ * @since 0.25.0
+ */
+ private IWordCheck wordCheckIpv4;
+
public IWordData wordData() {
return wordData;
}
@@ -355,4 +386,49 @@ public class SensitiveWordContext implements IWordContext {
this.wordResultCondition = wordResultCondition;
return this;
}
+
+ public IWordCheck wordCheckWord() {
+ return wordCheckWord;
+ }
+
+ public SensitiveWordContext wordCheckWord(IWordCheck wordCheckWord) {
+ this.wordCheckWord = wordCheckWord;
+ return this;
+ }
+
+ public IWordCheck wordCheckNum() {
+ return wordCheckNum;
+ }
+
+ public SensitiveWordContext wordCheckNum(IWordCheck wordCheckNum) {
+ this.wordCheckNum = wordCheckNum;
+ return this;
+ }
+
+ public IWordCheck wordCheckEmail() {
+ return wordCheckEmail;
+ }
+
+ public SensitiveWordContext wordCheckEmail(IWordCheck wordCheckEmail) {
+ this.wordCheckEmail = wordCheckEmail;
+ return this;
+ }
+
+ public IWordCheck wordCheckUrl() {
+ return wordCheckUrl;
+ }
+
+ public SensitiveWordContext wordCheckUrl(IWordCheck wordCheckUrl) {
+ this.wordCheckUrl = wordCheckUrl;
+ return this;
+ }
+
+ public IWordCheck wordCheckIpv4() {
+ return wordCheckIpv4;
+ }
+
+ public SensitiveWordContext wordCheckIpv4(IWordCheck wordCheckIpv4) {
+ this.wordCheckIpv4 = wordCheckIpv4;
+ return this;
+ }
}
diff --git a/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckUrl.java b/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckUrl.java
index 4ca748b..105b79c 100644
--- a/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckUrl.java
+++ b/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckUrl.java
@@ -60,7 +60,17 @@ public class WordCheckUrl extends AbstractConditionWordCheck {
// 改为 http:// 或者 https:// 开头
String string = stringBuilder.toString();
- return RegexUtil.isUrl(string);
+ return isUrl(string);
+ }
+
+ /**
+ * 是否为 URL
+ * @param text 原始文本
+ * @return 结果
+ * @since 0.25.0
+ */
+ protected boolean isUrl(final String text) {
+ return RegexUtil.isUrl(text);
}
}
diff --git a/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckUrlNoPrefix.java b/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckUrlNoPrefix.java
new file mode 100644
index 0000000..4a6a491
--- /dev/null
+++ b/src/main/java/com/github/houbb/sensitive/word/support/check/WordCheckUrlNoPrefix.java
@@ -0,0 +1,32 @@
+package com.github.houbb.sensitive.word.support.check;
+
+import com.github.houbb.heaven.util.util.regex.RegexUtil;
+import com.github.houbb.sensitive.word.api.IWordCheck;
+
+/**
+ * (1)暂时先粗略的处理 web-site
+ * (2)如果网址的最后为图片类型,则跳过。
+ * (3)长度超过 70,直接结束。
+ *
+ * 不包含前缀的实现策略
+ *
+ * @author binbin.hou
+ * @since 0.25.0
+ */
+public class WordCheckUrlNoPrefix extends WordCheckUrl {
+
+ /**
+ * @since 0.3.0
+ */
+ private static final IWordCheck INSTANCE = new WordCheckUrlNoPrefix();
+
+ public static IWordCheck getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ protected boolean isUrl(String text) {
+ return RegexUtil.isWebSite(text);
+ }
+
+}
diff --git a/src/main/java/com/github/houbb/sensitive/word/support/check/WordChecks.java b/src/main/java/com/github/houbb/sensitive/word/support/check/WordChecks.java
index 230bab2..d173c2d 100644
--- a/src/main/java/com/github/houbb/sensitive/word/support/check/WordChecks.java
+++ b/src/main/java/com/github/houbb/sensitive/word/support/check/WordChecks.java
@@ -77,4 +77,15 @@ public final class WordChecks {
return WordCheckIPV4.getInstance();
}
+ /**
+ * 不需要前缀的 urlPrefix
+ * 注意:这种检测方法可能会和代码中的包名称冲突
+ *
+ * @return 实现
+ * @since 0.25.0
+ */
+ public static IWordCheck urlNoPrefix() {
+ return WordCheckUrlNoPrefix.getInstance();
+ }
+
}
diff --git a/src/main/java/com/github/houbb/sensitive/word/support/combine/check/WordCheckCombine.java b/src/main/java/com/github/houbb/sensitive/word/support/combine/check/WordCheckCombine.java
index 60205fb..61fbbb0 100644
--- a/src/main/java/com/github/houbb/sensitive/word/support/combine/check/WordCheckCombine.java
+++ b/src/main/java/com/github/houbb/sensitive/word/support/combine/check/WordCheckCombine.java
@@ -18,19 +18,19 @@ public class WordCheckCombine extends AbstractWordCheckCombine {
List project: sensitive-word-SensitiveWordBsTest create on 2020/1/7 23:43