1、重构Template,其他模块使用之前Template的也相应修改为新的Template

This commit is contained in:
PushM
2024-05-21 16:08:29 +08:00
parent 20127d20e1
commit 1fd4612699
6 changed files with 81 additions and 46 deletions

View File

@@ -76,7 +76,7 @@ public class DynamicRuleObject {
@JsonProperty("template_id") @JsonProperty("template_id")
@Schema(description = "策略模板id", example = "1", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "策略模板id", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
private Integer templateId; private Integer templateId;
@NotNull // @NotNull
@JsonProperty("dynamic_rule_protect_level") @JsonProperty("dynamic_rule_protect_level")
@Max(value = 3) @Max(value = 3)
@Min(value = 1) @Min(value = 1)
@@ -91,7 +91,7 @@ public class DynamicRuleObject {
// @JsonProperty("dynamic_rule_range") // @JsonProperty("dynamic_rule_range")
// @Schema(description = "范围", example = "北京", requiredMode = Schema.RequiredMode.REQUIRED) // @Schema(description = "范围", example = "北京", requiredMode = Schema.RequiredMode.REQUIRED)
// private String dynamicRuleRange; // private String dynamicRuleRange;
@NotNull // @NotNull
@JsonProperty("dynamic_rule_frequency") @JsonProperty("dynamic_rule_frequency")
@Schema(description = "频率", example = "1", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "频率", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
private Integer dynamicRuleFrequency; private Integer dynamicRuleFrequency;

View File

@@ -1,7 +1,7 @@
package com.realtime.protection.server.rule.dynamicrule; package com.realtime.protection.server.rule.dynamicrule;
import com.realtime.protection.configuration.entity.defense.object.ProtectObject; import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
import com.realtime.protection.configuration.entity.defense.template.Template; import com.realtime.protection.configuration.entity.defense.template.TemplateNew;
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject; import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@@ -37,7 +37,7 @@ public interface DynamicRuleMapper {
void deleteDynamicRuleProtectObjectConcat(Integer dynamicRuleId); void deleteDynamicRuleProtectObjectConcat(Integer dynamicRuleId);
Template queryTemplateByRuleId(Integer dynamicRuleId); TemplateNew queryTemplateByRuleId(Integer dynamicRuleId);
boolean newDynamicRulProtectObjectsConcat(Integer dynamicRuleId, List<Integer> protectObjectIds); boolean newDynamicRulProtectObjectsConcat(Integer dynamicRuleId, List<Integer> protectObjectIds);

View File

@@ -2,6 +2,7 @@ package com.realtime.protection.server.rule.dynamicrule;
import com.alibaba.excel.util.ListUtils; import com.alibaba.excel.util.ListUtils;
import com.realtime.protection.configuration.entity.defense.template.Template; import com.realtime.protection.configuration.entity.defense.template.Template;
import com.realtime.protection.configuration.entity.defense.template.TemplateNew;
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject; import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
import com.realtime.protection.configuration.utils.Counter; import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper; import com.realtime.protection.configuration.utils.SqlSessionWrapper;
@@ -122,7 +123,7 @@ public class DynamicRuleService {
//查询DynamicRule关联的ProtectObject //查询DynamicRule关联的ProtectObject
dynamicRuleObject.setProtectObjects(dynamicRuleMapper.queryProtectObjectByRuleId(dynamicRuleId)); dynamicRuleObject.setProtectObjects(dynamicRuleMapper.queryProtectObjectByRuleId(dynamicRuleId));
//查询DynamicRule关联的template详细信息 //查询DynamicRule关联的template详细信息
Template template = dynamicRuleMapper.queryTemplateByRuleId(dynamicRuleId); TemplateNew template = dynamicRuleMapper.queryTemplateByRuleId(dynamicRuleId);
if (template == null){ if (template == null){
//template在表中删除了需要重新设置template感觉这种情况不多见 //template在表中删除了需要重新设置template感觉这种情况不多见
dynamicRuleObject.setDynamicRuleSourceSystem(null); dynamicRuleObject.setDynamicRuleSourceSystem(null);
@@ -130,6 +131,7 @@ public class DynamicRuleService {
}else{ }else{
dynamicRuleObject.setDynamicRuleSourceSystem(template.getSourceSystem()); dynamicRuleObject.setDynamicRuleSourceSystem(template.getSourceSystem());
dynamicRuleObject.setDynamicRuleEventType(template.getTemplateName()); dynamicRuleObject.setDynamicRuleEventType(template.getTemplateName());
dynamicRuleObject.setDynamicRuleProtectLevel(Integer.valueOf(template.getProtectLevel()));
} }
return dynamicRuleObject; return dynamicRuleObject;

View File

@@ -28,7 +28,7 @@
<result column="task_status" property="taskStatus"/> <result column="task_status" property="taskStatus"/>
</resultMap> </resultMap>
<resultMap id="protectLevelMap" type="com.realtime.protection.configuration.entity.defense.template.ProtectLevel"> <resultMap id="protectLevelMap" type="com.realtime.protection.configuration.entity.defense.template.ProtectLevel">
<id column="protect_level_id" property="protectLevelId"/> <!-- <id column="protect_level_id" property="protectLevelId"/>-->
<result column="has_protect_object_ip" property="hasProtectObjectIP"/> <result column="has_protect_object_ip" property="hasProtectObjectIP"/>
<result column="has_protect_object_port" property="hasProtectObjectPort"/> <result column="has_protect_object_port" property="hasProtectObjectPort"/>
<result column="has_peer_ip" property="hasPeerIP"/> <result column="has_peer_ip" property="hasPeerIP"/>
@@ -37,6 +37,7 @@
<result column="has_url" property="hasURL"/> <result column="has_url" property="hasURL"/>
<result column="has_dns" property="hasDNS"/> <result column="has_dns" property="hasDNS"/>
<result column="is_full_flow" property="isFullFlow"/> <result column="is_full_flow" property="isFullFlow"/>
<result column="is_protect_object_src" property="isProtectObjectIPSrc"/>
</resultMap> </resultMap>
<resultMap id="alertMessageMap" type="com.realtime.protection.configuration.entity.alert.AlertMessage"> <resultMap id="alertMessageMap" type="com.realtime.protection.configuration.entity.alert.AlertMessage">
@@ -109,28 +110,43 @@
</insert> </insert>
<!-- <select id="queryTemplateProtectLevel" resultMap="protectLevelMap">-->
<!-- SELECT-->
<!-- t_protect_level.protect_level_id,-->
<!-- t_protect_level.has_protect_object_ip,-->
<!-- t_protect_level.has_protect_object_port,-->
<!-- t_protect_level.has_peer_ip,-->
<!-- t_protect_level.has_peer_port,-->
<!-- t_protect_level.has_protocol,-->
<!-- t_protect_level.has_url,-->
<!-- t_protect_level.has_dns,-->
<!-- t_protect_level.is_full_flow-->
<!-- FROM t_strategy_template-->
<!-- <if test="protectLevel == 1">-->
<!-- left join t_protect_level on t_strategy_template.strategy_template_low_level_id = t_protect_level.protect_level_id-->
<!-- </if>-->
<!-- <if test="protectLevel == 2">-->
<!-- left join t_protect_level on t_strategy_template.strategy_template_medium_level_id = t_protect_level.protect_level_id-->
<!-- </if>-->
<!-- <if test="protectLevel == 3">-->
<!-- left join t_protect_level on t_strategy_template.strategy_template_high_level_id = t_protect_level.protect_level_id-->
<!-- </if>-->
<!-- WHERE t_strategy_template.strategy_template_id = #{templateId}-->
<!-- </select>-->
<select id="queryTemplateProtectLevel" resultMap="protectLevelMap"> <select id="queryTemplateProtectLevel" resultMap="protectLevelMap">
SELECT SELECT
t_protect_level.protect_level_id, has_protect_object_ip,
t_protect_level.has_protect_object_ip, has_protect_object_port,
t_protect_level.has_protect_object_port, has_peer_ip,
t_protect_level.has_peer_ip, has_peer_port,
t_protect_level.has_peer_port, has_protocol,
t_protect_level.has_protocol, has_url,
t_protect_level.has_url, has_dns,
t_protect_level.has_dns, is_full_flow,
t_protect_level.is_full_flow is_protect_object_src
FROM t_strategy_template FROM t_strategy_template_new
<if test="protectLevel == 1"> WHERE strategy_template_id = #{templateId}
left join t_protect_level on t_strategy_template.strategy_template_low_level_id = t_protect_level.protect_level_id
</if>
<if test="protectLevel == 2">
left join t_protect_level on t_strategy_template.strategy_template_medium_level_id = t_protect_level.protect_level_id
</if>
<if test="protectLevel == 3">
left join t_protect_level on t_strategy_template.strategy_template_high_level_id = t_protect_level.protect_level_id
</if>
WHERE t_strategy_template.strategy_template_id = #{templateId}
</select> </select>
<select id="getDynamicTaskInfos" <select id="getDynamicTaskInfos"
@@ -162,7 +178,7 @@
from t_task from t_task
left join realtime_protection.t_dynamic_rule t_dr on left join realtime_protection.t_dynamic_rule t_dr on
(t_task.task_id = t_dr.dynamic_rule_used_task_id and t_dr.dynamic_rule_id = #{dynamicRuleId}) (t_task.task_id = t_dr.dynamic_rule_used_task_id and t_dr.dynamic_rule_id = #{dynamicRuleId})
left join realtime_protection.t_strategy_template t_tmplate on left join realtime_protection.t_strategy_template_new t_tmplate on
( t_dr.template_id = t_tmplate.strategy_template_id ) ( t_dr.template_id = t_tmplate.strategy_template_id )
where where
t_task.task_id = #{taskId} t_task.task_id = #{taskId}

View File

@@ -174,13 +174,16 @@
<result column="dynamic_rule_create_username" property="dynamicRuleCreateUsername"/> <result column="dynamic_rule_create_username" property="dynamicRuleCreateUsername"/>
<result column="dynamic_rule_create_depart" property="dynamicRuleCreateDepart"/> <result column="dynamic_rule_create_depart" property="dynamicRuleCreateDepart"/>
<result column="template_id" property="templateId"/> <result column="template_id" property="templateId"/>
<result column="dynamic_rule_protect_level" property="dynamicRuleProtectLevel"/> <!-- <result column="dynamic_rule_protect_level" property="dynamicRuleProtectLevel"/>-->
<result column="dynamic_rule_priority" property="dynamicRulePriority"/> <result column="dynamic_rule_priority" property="dynamicRulePriority"/>
<result column="dynamic_rule_frequency" property="dynamicRuleFrequency"/> <result column="dynamic_rule_frequency" property="dynamicRuleFrequency"/>
<result column="audit_status" property="auditStatus"/> <result column="audit_status" property="auditStatus"/>
<!-- <result column="protect_object_id" property="protectObjectIds"/>--> <!-- <result column="protect_object_id" property="protectObjectIds"/>-->
<result column="strategy_template_name" property="dynamicRuleEventType"/> <result column="strategy_template_name" property="dynamicRuleEventType"/>
<result column="strategy_template_source_system" property="dynamicRuleSourceSystem"/> <result column="strategy_template_source_system" property="dynamicRuleSourceSystem"/>
<result column="event_type" property="dynamicRuleSourceSystem"/>
<result column="protect_level" property="dynamicRuleProtectLevel"/>
<result column="audit_status" property="auditStatus"/> <result column="audit_status" property="auditStatus"/>
<result column="dynamic_rule_display_id" property="dynamicRuleDisplayId"/> <result column="dynamic_rule_display_id" property="dynamicRuleDisplayId"/>
<result column="audit_user_name" property="auditUserName"/> <result column="audit_user_name" property="auditUserName"/>
@@ -222,8 +225,8 @@
from t_dynamic_rule from t_dynamic_rule
# left join t_protect_object_dynamic_rule_conn # left join t_protect_object_dynamic_rule_conn
# on t_dynamic_rule.dynamic_rule_id = t_protect_object_dynamic_rule_conn.dynamic_rule_id # on t_dynamic_rule.dynamic_rule_id = t_protect_object_dynamic_rule_conn.dynamic_rule_id
left join t_strategy_template left join t_strategy_template_new
on t_dynamic_rule.template_id = t_strategy_template.strategy_template_id on t_dynamic_rule.template_id = t_strategy_template_new.strategy_template_id
<where> <where>
<if test="dynamicRuleName != null and dynamicRuleName !=''" > <if test="dynamicRuleName != null and dynamicRuleName !=''" >
t_dynamic_rule.dynamic_rule_name like concat('%', #{dynamicRuleName}, '%') t_dynamic_rule.dynamic_rule_name like concat('%', #{dynamicRuleName}, '%')
@@ -232,7 +235,7 @@
and t_dynamic_rule.dynamic_rule_id = #{dynamicRuleId} and t_dynamic_rule.dynamic_rule_id = #{dynamicRuleId}
</if> </if>
<if test="sourceSystem != null and sourceSystem !=''"> <if test="sourceSystem != null and sourceSystem !=''">
and t_strategy_template.strategy_template_source_system = #{sourceSystem} and t_strategy_template_new.strategy_template_source_system = #{sourceSystem}
</if> </if>
<if test="creator != null and creator !=''"> <if test="creator != null and creator !=''">
and t_dynamic_rule.dynamic_rule_create_username = #{creator} and t_dynamic_rule.dynamic_rule_create_username = #{creator}
@@ -241,10 +244,10 @@
and t_dynamic_rule.audit_status = #{auditStatus} and t_dynamic_rule.audit_status = #{auditStatus}
</if> </if>
<if test="eventType != null and eventType !=''"> <if test="eventType != null and eventType !=''">
and t_strategy_template.strategy_template_name = #{eventType} and t_strategy_template_new.event_type = #{eventType}
</if> </if>
<if test="protectLevel != null"> <if test="protectLevel != null">
and t_dynamic_rule.dynamic_rule_protect_level = #{protectLevel} and t_strategy_template_new.protect_level = #{protectLevel}
</if> </if>
</where> </where>
@@ -252,17 +255,31 @@
</select> </select>
<resultMap id="templateMap" type="com.realtime.protection.configuration.entity.defense.template.Template"> <resultMap id="templateMap" type="com.realtime.protection.configuration.entity.defense.template.TemplateNew">
<id column="strategy_template_id" property="templateId"/> <id column="strategy_template_id" property="templateId"/>
<result column="strategy_template_name" property="templateName"/> <result column="strategy_template_name" property="templateName"/>
<result column="strategy_template_display_id" property="templateDisplayId"/>
<result column="strategy_template_source_system" property="sourceSystem"/> <result column="strategy_template_source_system" property="sourceSystem"/>
<result column="event_type" property="eventType"/>
<result column="protect_level" property="protectLevel"/>
<result column="strategy_template_description" property="description"/>
<result column="has_protect_object_ip" property="hasProtectObjectIP"/>
<result column="has_protect_object_port" property="hasProtectObjectPort"/>
<result column="has_protocol" property="hasProtocol"/>
<result column="has_url" property="hasURL"/>
<result column="has_dns" property="hasDNS"/>
<result column="has_peer_ip" property="hasPeerIP"/>
<result column="has_peer_port" property="hasPeerPort"/>
<result column="is_full_flow" property="isFullFlow"/>
<result column="is_protect_object_src" property="isProtectObjectIPSrc"/>
</resultMap> </resultMap>
<select id="queryTemplateByRuleId" resultMap="templateMap"> <select id="queryTemplateByRuleId" resultMap="templateMap">
select * select *
from t_strategy_template from t_strategy_template_new
inner join t_dynamic_rule inner join t_dynamic_rule
on t_strategy_template.strategy_template_id = t_dynamic_rule.template_id on t_strategy_template_new.strategy_template_id = t_dynamic_rule.template_id
where t_dynamic_rule.dynamic_rule_id = #{dynamicRuleId} where t_dynamic_rule.dynamic_rule_id = #{dynamicRuleId}
</select> </select>
<select id="queryProtectObjectById" resultType="java.lang.Boolean"> <select id="queryProtectObjectById" resultType="java.lang.Boolean">
@@ -274,8 +291,8 @@
<select id="queryDynamicRuleTotalNum" resultType="java.lang.Integer"> <select id="queryDynamicRuleTotalNum" resultType="java.lang.Integer">
SELECT COUNT(*) SELECT COUNT(*)
FROM t_dynamic_rule FROM t_dynamic_rule
left join t_strategy_template left join t_strategy_template_new
on t_dynamic_rule.template_id = t_strategy_template.strategy_template_id on t_dynamic_rule.template_id = t_strategy_template_new.strategy_template_id
<where> <where>
<if test="dynamicRuleName != null"> <if test="dynamicRuleName != null">
t_dynamic_rule.dynamic_rule_name like concat('%', #{dynamicRuleName}, '%') t_dynamic_rule.dynamic_rule_name like concat('%', #{dynamicRuleName}, '%')
@@ -284,7 +301,7 @@
and t_dynamic_rule.dynamic_rule_id = #{dynamicRuleId} and t_dynamic_rule.dynamic_rule_id = #{dynamicRuleId}
</if> </if>
<if test="sourceSystem != null"> <if test="sourceSystem != null">
and t_strategy_template.strategy_template_source_system = #{sourceSystem} and t_strategy_template_new.strategy_template_source_system = #{sourceSystem}
</if> </if>
<if test="creator != null"> <if test="creator != null">
and t_dynamic_rule.dynamic_rule_create_username = #{creator} and t_dynamic_rule.dynamic_rule_create_username = #{creator}
@@ -293,10 +310,10 @@
and t_dynamic_rule.audit_status = #{auditStatus} and t_dynamic_rule.audit_status = #{auditStatus}
</if> </if>
<if test="eventType != null and eventType !=''"> <if test="eventType != null and eventType !=''">
and t_strategy_template.strategy_template_name = #{eventType} and t_strategy_template_new.strategy_template_name = #{eventType}
</if> </if>
<if test="protectLevel != null"> <if test="protectLevel != null">
and t_dynamic_rule.dynamic_rule_protect_level = #{protectLevel} and t_strategy_template_new.protect_level = #{protectLevel}
</if> </if>
</where> </where>
</select> </select>
@@ -305,8 +322,8 @@
resultMap="dynamicRulePageQueryMap"> resultMap="dynamicRulePageQueryMap">
select * select *
from t_dynamic_rule from t_dynamic_rule
left join t_strategy_template left join t_strategy_template_new
on t_dynamic_rule.template_id = t_strategy_template.strategy_template_id on t_dynamic_rule.template_id = t_strategy_template_new.strategy_template_id
where dynamic_rule_id in where dynamic_rule_id in
<foreach collection="ids" item="id" open="(" separator="," close=")"> <foreach collection="ids" item="id" open="(" separator="," close=")">
#{id} #{id}

View File

@@ -354,8 +354,8 @@
task_start_time, task_start_time,
task_end_time, task_end_time,
tdr.dynamic_rule_id as rule_id, tdr.dynamic_rule_id as rule_id,
strategy_template_source_system as source_system, tst.strategy_template_source_system as source_system,
strategy_template_name as event_type, tst.event_type as event_type,
tdr.log_rule_id, tdr.log_rule_id,
INET_NTOA(protect_object_ip) as protect_object_ip, INET_NTOA(protect_object_ip) as protect_object_ip,
protect_object_port, protect_object_port,
@@ -366,7 +366,7 @@
LEFT JOIN realtime_protection.t_protect_object_dynamic_rule_conn tpodrc LEFT JOIN realtime_protection.t_protect_object_dynamic_rule_conn tpodrc
on tdr.dynamic_rule_id = tpodrc.dynamic_rule_id on tdr.dynamic_rule_id = tpodrc.dynamic_rule_id
LEFT JOIN realtime_protection.t_protect_object tpo on tpo.protect_object_id = tpodrc.protect_object_id LEFT JOIN realtime_protection.t_protect_object tpo on tpo.protect_object_id = tpodrc.protect_object_id
LEFT JOIN realtime_protection.t_strategy_template tst on tdr.template_id = tst.strategy_template_id LEFT JOIN realtime_protection.t_strategy_template_new tst on tdr.template_id = tst.strategy_template_id
WHERE task_id = #{task_id} WHERE task_id = #{task_id}
</select> </select>
<select id="queryTaskTotalNum" resultType="java.lang.Integer"> <select id="queryTaskTotalNum" resultType="java.lang.Integer">