Merge remote-tracking branch 'origin/haskafka' into haskafka

# Conflicts:
#	src/main/java/com/realtime/protection/server/task/TaskMapper.java
#	src/main/java/com/realtime/protection/server/task/TaskService.java
#	src/main/resources/mappers/TaskMapper.xml
This commit is contained in:
PushM
2024-05-07 22:38:18 +08:00
22 changed files with 217 additions and 40 deletions

View File

@@ -3,6 +3,7 @@ package com.realtime.protection.server.rule.dynamicrule;
import com.alibaba.excel.util.ListUtils;
import com.realtime.protection.configuration.entity.defense.template.Template;
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import com.realtime.protection.configuration.utils.enums.StateEnum;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
@@ -10,6 +11,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -20,11 +22,12 @@ import java.util.function.Function;
public class DynamicRuleService {
private final DynamicRuleMapper dynamicRuleMapper;
private final SqlSessionWrapper sqlSessionWrapper;
private final Counter counter;
public DynamicRuleService(DynamicRuleMapper dynamicRuleMapper, SqlSessionWrapper sqlSessionWrapper) {
public DynamicRuleService(DynamicRuleMapper dynamicRuleMapper, SqlSessionWrapper sqlSessionWrapper, Counter counter) {
this.sqlSessionWrapper = sqlSessionWrapper;
this.dynamicRuleMapper = dynamicRuleMapper;
this.counter = counter;
}
@Transactional
@@ -37,6 +40,13 @@ public class DynamicRuleService {
throw new IllegalArgumentException("protect object id is invalid");
}
dynamicRule.setDynamicRuleDisplayId(
"DTGZ-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
+ "-"
+ String.format("%06d", counter.generateId("dynamic_rule"))
);
dynamicRuleMapper.newDynamicRule(dynamicRule);
Integer dynamicRuleId = dynamicRule.getDynamicRuleId();
dynamicRule.getProtectObjectIds().forEach(
@@ -56,6 +66,12 @@ public class DynamicRuleService {
List<DynamicRuleObject> DynamicRuleIdBatch = ListUtils.newArrayListWithExpectedSize(100);
for (DynamicRuleObject dynamicRule : DynamicRuleList) {
dynamicRule.setDynamicRuleCreateTime(LocalDateTime.now());
dynamicRule.setDynamicRuleDisplayId(
"DTGZ-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
+ "-"
+ String.format("%06d", counter.generateId("dynamic_rule"))
);
DynamicRuleIdBatch.add(dynamicRule);
if (DynamicRuleIdBatch.size() < 100) {
continue;

View File

@@ -3,6 +3,7 @@ package com.realtime.protection.server.rule.staticrule;
import com.alibaba.excel.util.ListUtils;
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import com.realtime.protection.configuration.utils.enums.RuleEnum;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
@@ -30,12 +31,14 @@ public class StaticRuleService {
private final StaticRuleMapper staticRuleMapper;
private final SqlSessionWrapper sqlSessionWrapper;
private final WhiteListService whiteListService;
private final Counter counter;
public StaticRuleService(StaticRuleMapper staticRuleMapper, SqlSessionWrapper sqlSessionWrapper, WhiteListService whiteListService) {
public StaticRuleService(StaticRuleMapper staticRuleMapper, SqlSessionWrapper sqlSessionWrapper, WhiteListService whiteListService, Counter counter) {
this.staticRuleMapper = staticRuleMapper;
this.sqlSessionWrapper = sqlSessionWrapper;
this.whiteListService = whiteListService;
this.counter = counter;
}
private static int ipToInt(String ip) {
@@ -86,6 +89,14 @@ public class StaticRuleService {
whiteListsHit.forEach(item -> result.append(item.getWhiteListName()).append(" "));
throw new IllegalArgumentException("静态规则与白名单规则冲突,冲突白名单名称:"+result.toString().trim());
}
object.setStaticRuleDisplayId(
"JTGZ-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
+ "-"
+ String.format("%06d", counter.generateId("static_rule"))
);
staticRuleMapper.newStaticRuleObject(object);
return object.getStaticRuleId();
@@ -186,6 +197,12 @@ public class StaticRuleService {
List<StaticRuleObject> StaticRuleBatch = ListUtils.newArrayListWithExpectedSize(100);
for (StaticRuleObject staticRule : list) {
staticRule.setStaticRuleCreateTime(LocalDateTime.now());
staticRule.setStaticRuleDisplayId(
"JTGZ-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
+ "-"
+ String.format("%06d", counter.generateId("static_rule"))
);
StaticRuleBatch.add(staticRule);
if (StaticRuleBatch.size() < 100) {
continue;