Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/java/com/realtime/protection/server/rule/dynamicrule/DynamicRuleService.java # src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleService.java # src/main/java/com/realtime/protection/server/task/TaskService.java
This commit is contained in:
@@ -5,6 +5,17 @@ import json
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
import socket
|
||||
import struct
|
||||
|
||||
|
||||
def convert_ipv4_to_int(ip_str):
|
||||
binary_ip = socket.inet_aton(ip_str)
|
||||
# 使用 struct.unpack 解包二进制数据到一个大端整数
|
||||
ip_int = struct.unpack('!I', binary_ip)[0]
|
||||
return ip_int
|
||||
|
||||
|
||||
def convert_ipv4_address(ip_int):
|
||||
|
||||
return socket.inet_ntoa(struct.pack('!I', ip_int))
|
||||
@@ -31,6 +42,7 @@ def format_data_to_json(test_data):
|
||||
|
||||
src_ip_v4, dst_ip_v4, src_port_v4, dst_port_v4, protocol_v4 = parse_and_convert_ip(data_parts[1])
|
||||
|
||||
|
||||
formatted_data = {
|
||||
"task_id": 30650,
|
||||
"rule_id": 39,
|
||||
@@ -96,19 +108,26 @@ def kafka_send():
|
||||
if request.method == 'POST' and request.is_json:
|
||||
data = request.get_json()
|
||||
|
||||
base_data = "1702017420-1-175833107,1921297587-310737541-53420-6379-6-127-0,140717936336976-140717936336992-0-0-0-131-4481,0,000,440000,1,7,107,1,111,Amazon Data Services UK,0,0,440100,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,9,10060101189,tcp.banner=$5115"
|
||||
base_data = "1702017420-1-175833107,2682412653-760391609-53420-6379-6-127-0,140717936336976-140717936336992-0-0-0-131-4481,0,000,440000,1,7,107,1,111,Amazon Data Services UK,0,0,440100,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,9,10060101189,tcp.banner=$5115"
|
||||
base_data2 = "1702017420-1-175833107,760391609-2682412653-53420-6379-6-127-0,140717936336976-140717936336992-0-0-0-131-4481,0,000,440000,1,7,107,1,111,Amazon Data Services UK,0,0,440100,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,9,10060101189,tcp.banner=$5115"
|
||||
|
||||
for item in data:
|
||||
task_id = item.get('task_id', '')
|
||||
rule_id = item.get('rule_id', '')
|
||||
modified_data = f"{base_data}, {task_id}, {rule_id},{0}"
|
||||
modified_data2 = f"{base_data2}, {task_id}, {rule_id},{0}"
|
||||
HOST = '127.0.0.1'
|
||||
PORT = 65432
|
||||
print(modified_data)
|
||||
send_test_data(HOST, PORT, modified_data)
|
||||
send_test_data(HOST, PORT, modified_data2)
|
||||
|
||||
return jsonify({'message': 'Data processed successfully'}), 200
|
||||
return jsonify({"success": True, "code": 200}), 200
|
||||
|
||||
return jsonify({'error': 'Invalid request'}), 400
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host='0.0.0.0', port=8081, debug=True)
|
||||
print("convert_ipv4_to_int:", convert_ipv4_to_int("159.226.94.109"))
|
||||
print("convert_ipv4_to_int:", convert_ipv4_to_int("45.82.167.185"))
|
||||
app.run(host='0.0.0.0', port=8088, debug=True)
|
||||
@@ -100,5 +100,5 @@ def start_server(host, port, topic):
|
||||
if __name__ == "__main__":
|
||||
HOST = '127.0.0.1'
|
||||
PORT = 65432
|
||||
TOPIC = 'topic-test'
|
||||
TOPIC = 'topic-alert'
|
||||
start_server(HOST, PORT, TOPIC)
|
||||
|
||||
@@ -73,6 +73,11 @@ public class Template {
|
||||
@Schema(description = "防御策略模板创建人处室", example = "xxx", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String createDepart;
|
||||
|
||||
@JsonProperty("audit_status")
|
||||
@Schema(description = "防御策略模板审核状态(0为未审核,1为已退回,2为审核通过)", example = "1", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String auditStatus;
|
||||
|
||||
|
||||
/**
|
||||
* 设置是否含有日常/应急/紧急防护等级态字段的字段
|
||||
*/
|
||||
|
||||
@@ -60,5 +60,5 @@ public class WhiteListObject {
|
||||
@JsonProperty("audit_status")
|
||||
@ExcelIgnore
|
||||
@Schema(description = "白名单对象审核状态(0为未审核,1为已退回,2为审核通过)", example = "2")
|
||||
private String whiteListAuditStatus;
|
||||
private Integer whiteListAuditStatus;
|
||||
}
|
||||
|
||||
@@ -129,4 +129,46 @@ public class TemplateController implements TemplateControllerApi {
|
||||
AuditStatusEnum.getNumByState(AuditStatusEnum.PENDING.getState())
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 审批
|
||||
*/
|
||||
@GetMapping("/{id}/audit/{auditStatus}")
|
||||
public ResponseResult updateTemplateAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus) {
|
||||
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
|
||||
return new ResponseResult(400, "id or status is invalid")
|
||||
.setData("template_id", id)
|
||||
.setData("success", false);
|
||||
}
|
||||
return ResponseResult.ok()
|
||||
.addDataMap(templateService.updateAuditStatus(id, auditStatus))
|
||||
.setData("template_id", id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量审批
|
||||
*/
|
||||
/*
|
||||
@PostMapping("/auditbatch")
|
||||
public ResponseResult updateDynamicRuleAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||
List<Integer> errorIds = new ArrayList<>();
|
||||
for (Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
|
||||
Integer id = entry.getKey();
|
||||
Integer auditStatus = entry.getValue();
|
||||
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
}
|
||||
if (!errorIds.isEmpty()){
|
||||
return new ResponseResult(400, "id or status is invalid")
|
||||
.setData("staticRule_id", errorIds)
|
||||
.setData("success", false);
|
||||
}
|
||||
|
||||
return ResponseResult.ok();
|
||||
|
||||
// .setData("success",dynamicRuleService.updateAuditStatusBatch(idsWithAuditStatusMap));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -42,4 +42,8 @@ public interface TemplateMapper {
|
||||
Integer queryUsedTemplateTotalNum();
|
||||
|
||||
Integer queryAuditTemplateTotalNum(Integer auditState);
|
||||
|
||||
Integer queryAuditStatusById(Integer id);
|
||||
|
||||
Boolean updateAuditStatusById(Integer id, Integer auditStatus);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.realtime.protection.server.defense.template;
|
||||
|
||||
import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||
import lombok.SneakyThrows;
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class TemplateService {
|
||||
@@ -87,4 +90,66 @@ public class TemplateService {
|
||||
public Integer queryAuditTemplateTotalNum(Integer auditState) {
|
||||
return templateMapper.queryAuditTemplateTotalNum(auditState);
|
||||
}
|
||||
|
||||
public Map<String, Object> updateAuditStatus(Integer id, Integer auditStatus) {
|
||||
Integer originalAuditStatus = templateMapper.queryAuditStatusById(id);
|
||||
if (originalAuditStatus == null) {
|
||||
throw new IllegalArgumentException("cannot find audit status of static rule " + id + ", maybe static rule doesn't exist?");
|
||||
}
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
throw new IllegalArgumentException("invalid audit status");
|
||||
}
|
||||
Boolean success = templateMapper.updateAuditStatusById(id, auditStatus);
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("success", success);
|
||||
resultMap.put("audit_status", auditStatus);
|
||||
return resultMap;
|
||||
}
|
||||
/*
|
||||
|
||||
public Map<String, Object> updateAuditStatus(Integer id, Integer auditStatus) {
|
||||
Integer originalAuditStatus = templateMapper.queryAuditStatusById(id);
|
||||
if (originalAuditStatus == null) {
|
||||
throw new IllegalArgumentException("cannot find audit status of static rule " + id + ", maybe static rule doesn't exist?");
|
||||
}
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
throw new IllegalArgumentException("invalid audit status");
|
||||
}
|
||||
Boolean success = templateMapper.updateAuditStatusById(id, auditStatus);
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("success", success);
|
||||
resultMap.put("audit_status", auditStatus);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||
Function<DynamicRuleMapper, Function<Map<Integer, Integer>, Boolean>> updateDynamicRuleAuditStatusFunction =
|
||||
mapper -> map -> {
|
||||
if (map == null || map.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<Integer, Integer> idWithAuditStatusBatch = new HashMap<>();
|
||||
for (Map.Entry<Integer, Integer> item : map.entrySet()) {
|
||||
idWithAuditStatusBatch.put(item.getKey(), item.getValue());
|
||||
if (idWithAuditStatusBatch.size() < 100) {
|
||||
continue;
|
||||
}
|
||||
//mapper指的就是外层函数输入的参数,也就是WhiteListMapper
|
||||
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
|
||||
idWithAuditStatusBatch.clear();
|
||||
}
|
||||
if (!idWithAuditStatusBatch.isEmpty()) {
|
||||
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
//实现事务操作
|
||||
return sqlSessionWrapper.startBatchSession(DynamicRuleMapper.class, updateDynamicRuleAuditStatusFunction, idsWithAuditStatusMap);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class DynamicRuleController implements DynamicRuleControllerApi {
|
||||
public ResponseResult updateDynamicRuleAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus) {
|
||||
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
|
||||
return new ResponseResult(400, "id or status is invalid")
|
||||
.setData("staticRule_id", id)
|
||||
.setData("dynamicRule_id", id)
|
||||
.setData("success", false);
|
||||
}
|
||||
return ResponseResult.ok()
|
||||
|
||||
@@ -58,4 +58,6 @@ public interface DynamicRuleMapper {
|
||||
Boolean updateAuditStatusById(Integer dynamicRuleId, Integer auditStatus);
|
||||
|
||||
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
|
||||
|
||||
List<Integer> queryAuditStatusByIds(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idsWithAuditStatusMap);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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;
|
||||
import java.util.Map;
|
||||
@@ -227,6 +228,27 @@ public class DynamicRuleService {
|
||||
}
|
||||
|
||||
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||
//校验id和status是否合法
|
||||
List<Integer> originalAuditStatusList = dynamicRuleMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
|
||||
int index = 0;
|
||||
List<Integer> errorIds = new ArrayList<>();
|
||||
for(Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
|
||||
Integer id = entry.getKey();
|
||||
Integer auditStatus = entry.getValue();
|
||||
Integer originalAuditStatus = originalAuditStatusList.get(index);
|
||||
index++;
|
||||
if (originalAuditStatus == null) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
}
|
||||
if (!errorIds.isEmpty()){
|
||||
return new IllegalArgumentException("动态规则id不存在或无法修改为对应审核状态, errorIds: " + errorIds);
|
||||
}
|
||||
|
||||
|
||||
Function<DynamicRuleMapper, Function<Map<Integer, Integer>, Boolean>> updateDynamicRuleAuditStatusFunction =
|
||||
mapper -> map -> {
|
||||
if (map == null || map.isEmpty()) {
|
||||
|
||||
@@ -50,4 +50,6 @@ public interface StaticRuleMapper {
|
||||
Integer queryUsedStaticRuleTotalNum();
|
||||
|
||||
Integer queryAuditStaticRuleTotalNum(@Param("auditStatus")Integer auditStatus);
|
||||
|
||||
List<Integer> queryAuditStatusByIds(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idsWithAuditStatusMap);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@ 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.utils.Counter;
|
||||
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
|
||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||
import com.realtime.protection.configuration.utils.enums.RuleEnum;
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
||||
import com.realtime.protection.server.whitelist.WhiteListService;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -20,6 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
@@ -28,11 +31,14 @@ public class StaticRuleService {
|
||||
private final StaticRuleMapper staticRuleMapper;
|
||||
private final SqlSessionWrapper sqlSessionWrapper;
|
||||
private final Counter counter;
|
||||
private final WhiteListService whiteListService;
|
||||
|
||||
public StaticRuleService(StaticRuleMapper staticRuleMapper, SqlSessionWrapper sqlSessionWrapper, WhiteListService whiteListService, Counter counter) {
|
||||
|
||||
public StaticRuleService(StaticRuleMapper staticRuleMapper, SqlSessionWrapper sqlSessionWrapper, Counter counter) {
|
||||
this.staticRuleMapper = staticRuleMapper;
|
||||
this.sqlSessionWrapper = sqlSessionWrapper;
|
||||
this.counter = counter;
|
||||
this.whiteListService = whiteListService;
|
||||
}
|
||||
|
||||
private static int ipToInt(String ip) {
|
||||
@@ -80,6 +86,14 @@ public class StaticRuleService {
|
||||
+ String.format("%06d", counter.generateId("static_rule"))
|
||||
);
|
||||
|
||||
List<StaticRuleObject> staticRuleObjects = new ArrayList<>();
|
||||
staticRuleObjects.add(object);
|
||||
List<WhiteListObject> whiteListsHit = whiteListService.whiteListStaticRulesObjectCheck(staticRuleObjects);
|
||||
if (!whiteListsHit.isEmpty()) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
whiteListsHit.forEach(item -> result.append(item.getWhiteListName()).append(" "));
|
||||
throw new IllegalArgumentException("静态规则与白名单规则冲突,冲突白名单名称:"+result.toString().trim());
|
||||
}
|
||||
staticRuleMapper.newStaticRuleObject(object);
|
||||
|
||||
return object.getStaticRuleId();
|
||||
@@ -133,6 +147,15 @@ public class StaticRuleService {
|
||||
throw new IllegalArgumentException("静态规则不符合指定的配置方法,请参考规则模板以配置静态规则");
|
||||
}
|
||||
|
||||
List<StaticRuleObject> staticRuleObjects = new ArrayList<>();
|
||||
staticRuleObjects.add(object);
|
||||
List<WhiteListObject> whiteListsHit = whiteListService.whiteListStaticRulesObjectCheck(staticRuleObjects);
|
||||
if (!whiteListsHit.isEmpty()) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
whiteListsHit.forEach(item -> result.append(item.getWhiteListName()).append(" "));
|
||||
throw new IllegalArgumentException("静态规则与白名单规则冲突,冲突白名单名称:"+result.toString().trim());
|
||||
}
|
||||
|
||||
//判断当前静态规则是否能够修改---是否存在任务选择的静态规则??
|
||||
//按id查询该静态规则的used_task_id字段,如果不为空,则不能修改
|
||||
object.setStaticRuleModifyTime(LocalDateTime.now());
|
||||
@@ -234,6 +257,25 @@ public class StaticRuleService {
|
||||
}
|
||||
|
||||
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||
//校验id和status是否合法
|
||||
List<Integer> originalAuditStatusList = staticRuleMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
|
||||
int index = 0;
|
||||
List<Integer> errorIds = new ArrayList<>();
|
||||
for(Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
|
||||
Integer id = entry.getKey();
|
||||
Integer auditStatus = entry.getValue();
|
||||
Integer originalAuditStatus = originalAuditStatusList.get(index);
|
||||
index++;
|
||||
if (originalAuditStatus == null) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
}
|
||||
if (!errorIds.isEmpty()){
|
||||
return new IllegalArgumentException("静态规则id不存在或无法修改为对应审核状态, errorIds: " + errorIds);
|
||||
}
|
||||
|
||||
Function<StaticRuleMapper, Function<Map<Integer, Integer>, Boolean>> updateStaticRuleAuditStatusFunction =
|
||||
mapper -> map -> {
|
||||
|
||||
@@ -69,4 +69,6 @@ public interface TaskMapper {
|
||||
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
|
||||
|
||||
Integer queryAuditTaskTotalNum(Integer auditState);
|
||||
|
||||
List<Integer> queryAuditStatusByIds(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idsWithAuditStatusMap);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -339,6 +340,26 @@ public class TaskService {
|
||||
}
|
||||
|
||||
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||
//校验id和status是否合法
|
||||
List<Integer> originalAuditStatusList = taskMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
|
||||
int index = 0;
|
||||
List<Integer> errorIds = new ArrayList<>();
|
||||
for(Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
|
||||
Integer id = entry.getKey();
|
||||
Integer auditStatus = entry.getValue();
|
||||
Integer originalAuditStatus = originalAuditStatusList.get(index);
|
||||
index++;
|
||||
if (originalAuditStatus == null) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
}
|
||||
if (!errorIds.isEmpty()){
|
||||
return new IllegalArgumentException("动态规则id不存在或无法修改为对应审核状态, errorIds: " + errorIds);
|
||||
}
|
||||
|
||||
Function<TaskMapper, Function<Map<Integer, Integer>, Boolean>> updateTaskAuditStatusFunction =
|
||||
mapper -> map -> {
|
||||
if (map == null || map.isEmpty()) {
|
||||
|
||||
@@ -107,7 +107,7 @@ public class WhiteListService {
|
||||
throw new IllegalStateException("无法修改白名单信息,因为其并未处于" + AuditStatusEnum.AUDITED + "状态");
|
||||
}
|
||||
|
||||
object.setWhiteListAuditStatus(AuditStatusEnum.PENDING.toString());
|
||||
object.setWhiteListAuditStatus(AuditStatusEnum.PENDING.getNum());
|
||||
|
||||
return whiteListMapper.updateWhiteListObject(id, object);
|
||||
}
|
||||
@@ -157,6 +157,12 @@ public class WhiteListService {
|
||||
List<StaticRuleObject> staticRuleObjects = staticRuleMapper.queryStaticRuleByIds(staticRuleId);
|
||||
return whiteListMapper.whiteListCStaticRulesCheck(staticRuleObjects);
|
||||
|
||||
}
|
||||
public List<WhiteListObject> whiteListStaticRulesObjectCheck(List<StaticRuleObject> staticRuleObjects) {
|
||||
//参数应该是指令,不管动态静态
|
||||
// 命中的whitelist列表:每一列包含ip port url
|
||||
return whiteListMapper.whiteListCStaticRulesCheck(staticRuleObjects);
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
||||
@@ -146,7 +146,7 @@
|
||||
<result column="dynamic_rule_create_username" property="dynamicRuleCreateUsername"/>
|
||||
<result column="dynamic_rule_create_depart" property="dynamicRuleCreateDepart"/>
|
||||
<result column="template_id" property="templateId"/>
|
||||
<result column="dynamic_rule_protec_level" property="dynamicRuleProtectLevel"/>
|
||||
<result column="dynamic_rule_protect_level" property="dynamicRuleProtectLevel"/>
|
||||
<result column="dynamic_rule_priority" property="dynamicRulePriority"/>
|
||||
<result column="dynamic_rule_range" property="dynamicRuleRange"/>
|
||||
<result column="dynamic_rule_frequency" property="dynamicRuleFrequency"/>
|
||||
@@ -283,6 +283,14 @@
|
||||
from t_dynamic_rule
|
||||
where dynamic_rule_id = #{dynamicRuleId}
|
||||
</select>
|
||||
<select id="queryAuditStatusByIds" resultType="java.lang.Integer">
|
||||
select audit_status
|
||||
from t_dynamic_rule
|
||||
where dynamic_rule_id in
|
||||
<foreach collection="idsWithAuditStatusMap" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -219,4 +219,13 @@
|
||||
WHERE static_rule_audit_status = #{auditStatus}
|
||||
</select>
|
||||
|
||||
<select id="queryAuditStatusByIds" resultType="java.lang.Integer">
|
||||
SELECT static_rule_audit_status
|
||||
FROM t_static_rule
|
||||
WHERE static_rule_id IN
|
||||
<foreach collection="idWithAuditStatusBatch" index="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -340,4 +340,12 @@
|
||||
SELECT COUNT(*) FROM t_task
|
||||
WHERE task_audit_status = #{auditStatus}
|
||||
</select>
|
||||
<select id="queryAuditStatusByIds" resultType="java.lang.Integer">
|
||||
SELECT task_audit_status
|
||||
FROM t_task
|
||||
WHERE task_id IN
|
||||
<foreach collection="idWithAuditStatusBatch" item="taskId" open="(" separator="," close=")">
|
||||
#{taskId}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -36,6 +36,7 @@
|
||||
<result column="strategy_template_used_times" property="usedTimes"/>
|
||||
<result column="strategy_template_running_tasks" property="runningTasks"/>
|
||||
<result column="strategy_template_description" property="description"/>
|
||||
<result column="audit_status" property="auditStatus"/>
|
||||
|
||||
<association property="protectLevelLow"
|
||||
javaType="com.realtime.protection.configuration.entity.defense.template.ProtectLevel">
|
||||
@@ -157,6 +158,12 @@
|
||||
WHERE audit_state = #{auditState}
|
||||
</select>
|
||||
|
||||
<select id="queryAuditStatusById" resultType="java.lang.Integer">
|
||||
SELECT audit_state
|
||||
FROM t_strategy_template
|
||||
WHERE strategy_template_id = #{id}
|
||||
</select>
|
||||
|
||||
<update id="updateTemplateInformation">
|
||||
UPDATE t_strategy_template
|
||||
<set>
|
||||
@@ -168,4 +175,10 @@
|
||||
AND strategy_template_id = #{template.templateId}
|
||||
</where>
|
||||
</update>
|
||||
|
||||
<update id="updateAuditStatusById">
|
||||
UPDATE t_strategy_template
|
||||
SET audit_state = #{auditState}
|
||||
WHERE strategy_template_id = #{id}
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -68,7 +68,7 @@ class TemplateServiceTest extends ProtectionApplicationTests {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
assertThrows(DuplicateKeyException.class, () -> {
|
||||
Integer templateId = templateService.newTemplate(template);
|
||||
assertTrue(templateId > 0);
|
||||
@@ -84,13 +84,14 @@ class TemplateServiceTest extends ProtectionApplicationTests {
|
||||
@Test
|
||||
void testQueryTemplate() {
|
||||
List<Template> templates = templateService.queryTemplates(
|
||||
"DDOS", null, null,1, 5);
|
||||
assertEquals(5, templates.size());
|
||||
for (Template template : templates) {
|
||||
assertTrue(template.getTemplateId() > 0);
|
||||
assertNotNull(template.getUsedTimes());
|
||||
assertNotNull(template.getRunningTasks());
|
||||
}
|
||||
null, null, null,1, 5);
|
||||
templates.forEach(item -> System.out.println(item)) ;
|
||||
//// assertEquals(5, templates.size());
|
||||
// for (Template template : templates) {i
|
||||
// assertTrue(template.getTemplateId() > 0);
|
||||
// assertNotNull(template.getUsedTimes());
|
||||
// assertNotNull(template.getRunningTasks());
|
||||
// }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -32,12 +32,11 @@ public class StaticRuleServiceTest extends ProtectionApplicationTests {
|
||||
staticRuleTest.setStaticRuleCreateUserId(2);
|
||||
staticRuleTest.setAuditStatus(0);
|
||||
|
||||
staticRuleTest.setStaticRuleSip("1.1.2.0");
|
||||
staticRuleTest.setStaticRuleMsip("255.255.255.0");
|
||||
staticRuleTest.setStaticRuleSip("2.2.2.2");
|
||||
|
||||
// staticRuleTest.setStaticRuleDip("1.1.1.2");
|
||||
// staticRuleTest.setStaticRuleMdip("255.255.255.0");
|
||||
staticRuleTest.setStaticRuleSport(80);
|
||||
staticRuleTest.setStaticRuleSport(11);
|
||||
|
||||
staticRuleTest.setStaticRulePriority(1);
|
||||
staticRuleTest.setStaticRuleFrequency(1);
|
||||
@@ -106,9 +105,9 @@ public class StaticRuleServiceTest extends ProtectionApplicationTests {
|
||||
@Test
|
||||
void testUpdateStaticRuleAuditStatusBatch(){
|
||||
Map<Integer, Integer> map = new HashMap<>();
|
||||
map.put(1299, 0);
|
||||
map.put(1300, 1);
|
||||
map.put(1301, 1);
|
||||
map.put(1325, 0);
|
||||
map.put(1326, 1);
|
||||
map.put(1328, 1);
|
||||
|
||||
|
||||
System.out.println(staticRuleService.updateAuditStatusBatch(map));
|
||||
|
||||
@@ -67,7 +67,7 @@ class WhiteListServiceTest extends ProtectionApplicationTests {
|
||||
//object.setWhiteListId(7);
|
||||
object.setWhiteListName("test_update");
|
||||
|
||||
whiteListService.updateWhiteListObject(7, object);
|
||||
whiteListService.updateWhiteListObject(7189, object);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user