|
|
|
@ -15,7 +15,6 @@ import cn.hutool.json.JSONUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.github.houbb.sensitive.word.api.IWordDeny; |
|
|
|
import com.github.houbb.sensitive.word.bs.SensitiveWordBs; |
|
|
|
import com.github.houbb.sensitive.word.support.deny.WordDenys; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -130,11 +129,16 @@ public class IeSecurityAuditServiceImpl implements IeSecurityAuditService { |
|
|
|
result.setBlocked(true); |
|
|
|
result.getHitWords().add("aliyun:" + aliResult.getRiskLevel()); |
|
|
|
result.getHitCategories().add(CharSequenceUtil.isBlank(aliResult.getRiskLevel()) ? "aliyun" : aliResult.getRiskLevel()); |
|
|
|
} else if (maxLevel == 1 && aliResult.isPass() && !isAliyunMediumOrHigh(aliResult.getRiskLevel())) { |
|
|
|
// 本地低风险词库容易覆盖地名/常用词。阿里云明确无中高风险时,以阿里云结论为准,避免正常聊天被替换成 ***。
|
|
|
|
result.setFilteredContent(content); |
|
|
|
result.setAuditStatus(IeConstants.AUDIT_PASS); |
|
|
|
result.setRiskLevel(IeConstants.RISK_NONE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(result.getHitWords())) { |
|
|
|
auditLogService.recordLog(bizType, bizId, userId, content, filtered, |
|
|
|
auditLogService.recordLog(bizType, bizId, userId, content, result.getFilteredContent(), |
|
|
|
result.getAuditStatus(), result.getRiskLevel(), |
|
|
|
String.join(",", result.getHitWords()), |
|
|
|
result.getHitCategories().stream().distinct().collect(Collectors.joining(","))); |
|
|
|
@ -164,6 +168,10 @@ public class IeSecurityAuditServiceImpl implements IeSecurityAuditService { |
|
|
|
.replace(" ", ""); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean isAliyunMediumOrHigh(String riskLevel) { |
|
|
|
return "medium".equalsIgnoreCase(riskLevel) || "high".equalsIgnoreCase(riskLevel); |
|
|
|
} |
|
|
|
|
|
|
|
private SensitiveWordBs getSensitiveWordBs() { |
|
|
|
long now = System.currentTimeMillis(); |
|
|
|
if (cachedWordBs != null && now < cachedExpireAt) { |
|
|
|
@ -188,12 +196,12 @@ public class IeSecurityAuditServiceImpl implements IeSecurityAuditService { |
|
|
|
.filter(CharSequenceUtil::isNotBlank) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
return SensitiveWordBs.newInstance() |
|
|
|
.wordDeny(WordDenys.chains(WordDenys.defaults(), new IWordDeny() { |
|
|
|
.wordDeny(new IWordDeny() { |
|
|
|
@Override |
|
|
|
public List<String> deny() { |
|
|
|
return denyWords; |
|
|
|
} |
|
|
|
})) |
|
|
|
}) |
|
|
|
.ignoreCase(true) |
|
|
|
.ignoreWidth(true) |
|
|
|
.ignoreNumStyle(true) |
|
|
|
|