1. 更新防护对象和模板的查询,添加更多筛选条件

This commit is contained in:
EnderByEndera
2024-01-31 18:28:25 +08:00
parent 384c48ae78
commit 67b0fdc3b8
16 changed files with 278 additions and 49 deletions

19
docker-doris/Dockerfile Normal file
View File

@@ -0,0 +1,19 @@
FROM apache/incubator-doris:build-env-latest
USER root
WORKDIR /root
RUN echo '123456' | passwd root --stdin
RUN yum install -y vim net-tools man wget git mysql lsof bash-completion \
&& cp /var/local/thirdparty/installed/bin/thrift /usr/bin
# 更安全的使用,创建用户而不是使用 root
RUN yum install -y sudo \
&& useradd -ms /bin/bash endera && echo 123456 | passwd endera --stdin \
&& usermod -a -G wheel endera
USER endera
WORKDIR /home/endera
RUN git config --global color.ui true \
&& git config --global user.email "707475564@qq.com" \
&& git config --global user.name "EnderByEndera"

View File

@@ -11,9 +11,9 @@ COPY realtime_protection realtime_protection
# NGINX_SERVER_NAME="localhost"
ENV SPRINGBOOT_FIRST_URL="192.168.107.89:8081" \
SPRINGBOOT_SECOND_URL="172.24.100.53:8082" \
SPRINGBOOT_THIRD_URL="172.24.100.53:8083" \
SPRINGBOOT_FOURTH_URL="172.24.100.53:8084" \
SPRINGBOOT_SECOND_URL="192.168.107.89:8082" \
SPRINGBOOT_THIRD_URL="192.168.107.89:8083" \
SPRINGBOOT_FOURTH_URL="192.168.107.89:8084" \
NGINX_PORT=8080 \
NGINX_SERVER_NAME="localhost"

View File

@@ -3,19 +3,19 @@ LABEL authors="Endera"
COPY realtime_protection realtime_protection
ENV MYSQL_USERNAME="root" \
MYSQL_PASSWD="IOmysql" \
MYSQL_URL="10.58.72.140:3306" \
DORIS_USERNAME="root" \
DORIS_PASSWD="" \
DORIS_URL="10.58.72.135:9030"
#ENV MYSQL_USERNAME="root" \
# MYSQL_PASSWD="aiihhbfcsy123!@#" \
# MYSQL_URL="192.168.107.89:3306" \
# MYSQL_PASSWD="IOmysql" \
# MYSQL_URL="10.58.72.140:3306" \
# DORIS_USERNAME="root" \
# DORIS_PASSWD="" \
# DORIS_URL="10.26.22.133:9030"
# DORIS_URL="10.58.72.135:9030"
ENV MYSQL_USERNAME="root" \
MYSQL_PASSWD="aiihhbfcsy123!@#" \
MYSQL_URL="192.168.107.89:3306" \
DORIS_USERNAME="root" \
DORIS_PASSWD="" \
DORIS_URL="10.26.22.133:9030"
EXPOSE 8081

View File

@@ -11,4 +11,4 @@ chmod +x ./gradlew
./gradlew clean && ./gradlew bootJar
# 启动SpringBoot服务
./gradlew bootRun --args="--spring.profiles.active=prod"
./gradlew bootRun --args="--spring.profiles.active=test"

View File

@@ -70,14 +70,38 @@ public class ProtectObjectController implements ProtectObjectControllerApi {
@GetMapping("/query")
public ResponseResult queryProtectObjects(@RequestParam(value = "proobj_name", required = false)
String protectObjectName,
@RequestParam(value = "proobj_id", required = false) @Min(1)
@RequestParam(value = "proobj_id", required = false)
@Min(value = 1, message = "ID值不可小于1")
Integer protectObjectId,
@RequestParam(value = "proobj_systemm_name", required = false)
String protectObjectSystemName,
@RequestParam(value = "proobj_ip_address", required = false)
String protectObjectIPAddress,
@RequestParam(value = "proobj_port_min", required = false)
Integer protectObjectPortMin,
@RequestParam(value = "proobj_port_max", required = false)
Integer protectObjectPortMax,
@RequestParam(value = "proobj_url", required = false)
String protectObjectURL,
@RequestParam(value = "proobj_protocol", required = false)
String protectObjectProtocol,
@RequestParam(value = "proobj_create_username", required = false)
String protectObjectCreateUsername,
@RequestParam(value = "proobj_audit_status", required = false)
Integer protectObjectAuditStatus,
@RequestParam("page") @Min(1) Integer page,
@RequestParam("page_size") @Min(1) Integer pageSize) {
return ResponseResult.ok()
.setData("proobj_list", protectObjectService.queryProtectObjects(protectObjectName,
protectObjectId, page, pageSize))
.setData("total_num", protectObjectService.queryProtectObjectsTotalNum(protectObjectName, protectObjectId));
.setData("proobj_list", protectObjectService.queryProtectObjects(
protectObjectName, protectObjectId, protectObjectSystemName, protectObjectIPAddress,
protectObjectPortMin, protectObjectPortMax, protectObjectURL, protectObjectProtocol,
protectObjectCreateUsername, protectObjectAuditStatus,
page, pageSize))
.setData("total_num", protectObjectService.queryProtectObjectsTotalNum(
protectObjectName, protectObjectId, protectObjectSystemName, protectObjectIPAddress,
protectObjectPortMin, protectObjectPortMax, protectObjectURL, protectObjectProtocol,
protectObjectCreateUsername, protectObjectAuditStatus
));
}
@Override

View File

@@ -158,14 +158,39 @@ public interface ProtectObjectControllerApi {
parameters = {
@Parameter(name = "proobj_name", description = "防护对象名称"),
@Parameter(name = "proobj_id", description = "防护对象ID"),
@Parameter(name = "proobj_system_name", description = "防护对象操作系统"),
@Parameter(name = "proobj_ip_address", description = "防护对象IP地址"),
@Parameter(name = "proobj_port_min", description = "防护对象端口最小值"),
@Parameter(name = "proobj_port_max", description = "防护对象端口最大值"),
@Parameter(name = "proobj_url", description = "防护对象URL"),
@Parameter(name = "proobj_protocol", description = "防护对象网络协议"),
@Parameter(name = "proobj_create_username", description = "防护对象创建人"),
@Parameter(name = "proobj_audit_status", description = "防护对象审核状态"),
@Parameter(name = "page", description = "页码", example = "1"),
@Parameter(name = "page_size", description = "每页的对象个数", example = "5")
}
)
ResponseResult queryProtectObjects(@RequestParam(value = "proobj_name", required = false)
String protectObjectName,
@RequestParam(value = "proobj_id", required = false) @Min(1)
@RequestParam(value = "proobj_id", required = false)
@Min(value = 1, message = "ID值不可小于1")
Integer protectObjectId,
@RequestParam(value = "proobj_systemm_name", required = false)
String protectObjectSystemName,
@RequestParam(value = "proobj_ip_address", required = false)
String protectObjectIPAddress,
@RequestParam(value = "proobj_port_min", required = false)
Integer protectObjectPortMin,
@RequestParam(value = "proobj_port_max", required = false)
Integer protectObjectPortMax,
@RequestParam(value = "proobj_url", required = false)
String protectObjectURL,
@RequestParam(value = "proobj_protocol", required = false)
String protectObjectProtocol,
@RequestParam(value = "proobj_create_username", required = false)
String protectObjectCreateUsername,
@RequestParam(value = "proobj_audit_status", required = false)
Integer protectObjectAuditStatus,
@RequestParam("page") @Min(1) Integer page,
@RequestParam("page_size") @Min(1) Integer pageSize);

View File

@@ -12,10 +12,6 @@ public interface ProtectObjectMapper {
void newProtectObjects(@Param("proobjs") List<ProtectObject> protectObject);
List<ProtectObject> queryProtectObjects(@Param("proobj_name") String protectObjectName,
@Param("proobj_id") Integer protectObjectId,
@Param("page") Integer page,
@Param("page_size") Integer pageSize);
ProtectObject queryProtectObject(@Param("proobj_id") Integer protectObjectId);
@@ -30,5 +26,26 @@ public interface ProtectObjectMapper {
Integer queryProtectObjectsTotalNum(@Param("proobj_name") String protectObjectName,
@Param("proobj_id") Integer protectObjectId);
@Param("proobj_id") Integer protectObjectId,
@Param("proobj_system_name") String protectObjectSystemName,
@Param("proobj_ip") String protectObjectIPAddress,
@Param("proobj_port_min") Integer protectObjectPortMin,
@Param("proobj_port_max") Integer protectObjectPortMax,
@Param("proobj_url") String protectObjectURL,
@Param("proobj_protocol") String protectObjectProtocol,
@Param("proobj_username") String protectObjectCreateUsername,
@Param("proobj_audit_status") Integer protectObjectAuditStatus);
List<ProtectObject> queryProtectObjects(@Param("proobj_name") String protectObjectName,
@Param("proobj_id") Integer protectObjectId,
@Param("proobj_system_name") String protectObjectSystemName,
@Param("proobj_ip") String protectObjectIPAddress,
@Param("proobj_port_min") Integer protectObjectPortMin,
@Param("proobj_port_max") Integer protectObjectPortMax,
@Param("proobj_url") String protectObjectURL,
@Param("proobj_protocol") String protectObjectProtocol,
@Param("proobj_username") String protectObjectCreateUsername,
@Param("proobj_audit_status") Integer protectObjectAuditStatus,
@Param("page") Integer page,
@Param("page_size") Integer pageSize);
}

View File

@@ -56,8 +56,17 @@ public class ProtectObjectService {
return sqlSessionWrapper.startBatchSession(ProtectObjectMapper.class, newProtectObjectFunction, protectObjectList);
}
public List<ProtectObject> queryProtectObjects(String protectObjectName, Integer protectObjectId, Integer page, Integer pageSize) {
return protectObjectMapper.queryProtectObjects(protectObjectName, protectObjectId, page, pageSize);
public List<ProtectObject> queryProtectObjects(String protectObjectName, Integer protectObjectId,
String protectObjectSystemName, String protectObjectIPAddress,
Integer protectObjectPortMin, Integer protectObjectPortMax,
String protectObjectURL, String protectObjectProtocol,
String protectObjectCreateUsername, Integer protectObjectAuditStatus,
Integer page, Integer pageSize) {
return protectObjectMapper.queryProtectObjects(
protectObjectName, protectObjectId, protectObjectSystemName, protectObjectIPAddress,
protectObjectPortMin, protectObjectPortMax, protectObjectURL, protectObjectProtocol,
protectObjectCreateUsername, protectObjectAuditStatus,
page, pageSize);
}
public ProtectObject queryProtectObject(Integer protectObjectId) {
@@ -113,7 +122,15 @@ public class ProtectObjectService {
return resultMap;
}
public Integer queryProtectObjectsTotalNum(String protectObjectName, Integer protectObjectId) {
return protectObjectMapper.queryProtectObjectsTotalNum(protectObjectName, protectObjectId);
public Integer queryProtectObjectsTotalNum(String protectObjectName, Integer protectObjectId,
String protectObjectSystemName, String protectObjectIPAddress,
Integer protectObjectPortMin, Integer protectObjectPortMax,
String protectObjectURL, String protectObjectProtocol,
String protectObjectCreateUsername, Integer protectObjectAuditStatus) {
return protectObjectMapper.queryProtectObjectsTotalNum(
protectObjectName, protectObjectId, protectObjectSystemName, protectObjectIPAddress,
protectObjectPortMin, protectObjectPortMax, protectObjectURL, protectObjectProtocol,
protectObjectCreateUsername, protectObjectAuditStatus
);
}
}

View File

@@ -39,13 +39,18 @@ public class TemplateController implements TemplateControllerApi {
@Override
@GetMapping("/query")
public ResponseResult queryTemplates(@RequestParam(value = "template_name", required = false) String templateName,
@RequestParam(value = "source_system", required = false) String sourceSystem,
@RequestParam(value = "create_user_name", required = false) String createUserName,
@RequestParam("page") @Min(1) Integer page,
@RequestParam("page_size") @Min(1) Integer pageSize) {
List<Template> templates = templateService.queryTemplates(templateName, page, pageSize);
List<Template> templates = templateService.queryTemplates(
templateName, sourceSystem, createUserName,
page, pageSize
);
return ResponseResult.ok()
.setData("templates", templates)
.setData("total_num", templateService.queryTemplateTotalNum(templateName));
.setData("total_num", templateService.queryTemplateTotalNum(templateName, sourceSystem, createUserName));
}
@Override

View File

@@ -168,11 +168,15 @@ public interface TemplateControllerApi {
},
parameters = {
@Parameter(name = "template_name", description = "防御策略模板名称", example = "DDOS"),
@Parameter(name = "source_system", description = "策略模板来源那系统", example = "xxx系统"),
@Parameter(name = "create_user_name", description = "创建人名称", example = "xxx"),
@Parameter(name = "page", description = "页码", example = "1"),
@Parameter(name = "page_size", description = "每页对象数量", example = "5")
}
)
ResponseResult queryTemplates(@RequestParam(value = "template_name", required = false) String templateName,
@RequestParam(value = "source_system", required = false) String sourceSystem,
@RequestParam(value = "create_user_name", required = false) String createUserName,
@RequestParam("page") @Min(1) Integer page,
@RequestParam("page_size") @Min(1) Integer pageSize);
@@ -379,6 +383,5 @@ public interface TemplateControllerApi {
)
}
)
public ResponseResult queryTemplateId(@RequestBody Map<String,String> map);
ResponseResult queryTemplateId(@RequestBody Map<String, String> map);
}

View File

@@ -15,6 +15,8 @@ public interface TemplateMapper {
void newProtectLevel(@Param("level") ProtectLevel protectLevel);
List<Template> queryTemplates(@Param("template_name") String templateName,
@Param("source_system") String sourceSystem,
@Param("create_username") String createUsername,
@Param("page") Integer page,
@Param("page_size") Integer pageSize);
@@ -27,7 +29,9 @@ public interface TemplateMapper {
@Delete("DELETE FROM t_strategy_template WHERE strategy_template_id = #{template_id}")
Boolean deleteTemplate(@Param("template_id") Integer templateId);
Integer queryTemplateTotalNum(String templateName);
Integer queryTemplateTotalNum(@Param("template_name") String templateName,
@Param("source_system") String sourceSystem,
@Param("create_username") String createUsername);
List<String> querySourceSystem();

View File

@@ -29,8 +29,9 @@ public class TemplateService {
return template.getTemplateId();
}
public List<Template> queryTemplates(String templateName, Integer page, Integer pageSize) {
return templateMapper.queryTemplates(templateName, page, pageSize);
public List<Template> queryTemplates(String templateName, String sourceSystem, String createUserName,
Integer page, Integer pageSize) {
return templateMapper.queryTemplates(templateName, sourceSystem, createUserName, page, pageSize);
}
public Boolean updateTemplate(Integer templateId, Template template) {
@@ -47,8 +48,8 @@ public class TemplateService {
return templateMapper.deleteTemplate(templateId);
}
public Integer queryTemplateTotalNum(String templateName) {
return templateMapper.queryTemplateTotalNum(templateName);
public Integer queryTemplateTotalNum(String templateName, String sourceSystem, String createUserName) {
return templateMapper.queryTemplateTotalNum(templateName, sourceSystem, createUserName);
}
public List<String> querySourceSystem() {

View File

@@ -51,8 +51,35 @@
protect_object_port, protect_object_url, protect_object_protocol, protect_object_audit_status
FROM t_protect_object
<where>
<if test="proobj_name != null">protect_object_name LIKE CONCAT('%', #{proobj_name}, '%')</if>
<if test="proobj_id != null">protect_object_id = #{proobj_id}</if>
<if test="proobj_name != null">AND protect_object_name LIKE CONCAT('%', #{proobj_name}, '%')</if>
<if test="proobj_id != null">AND protect_object_id = #{proobj_id}</if>
<if test="proobj_system_name != null">
AND protect_object_system_name LIKE CONCAT('%', #{proobj_system_name}, '%')
</if>
<if test="proobj_ip != null">
AND protect_object_id IN (
SELECT protect_object_id FROM t_protect_object_inet_addr_view tpo_view
WHERE tpo_view.protect_object_ip LIKE CONCAT('%', #{proobj_ip}, '%')
)
</if>
<if test="proobj_port_min != null">
AND protect_object_port &gt; #{proobj_port_min}
</if>
<if test="proobj_port_max != null">
AND protect_object_port &lt; #{proobj_port_max}
</if>
<if test="proobj_url != null">
AND protect_object_url LIKE CONCAT('%', #{proobj_url}, '%')
</if>
<if test="proobj_protocol != null">
AND protect_object_protocol = #{proobj_protocol}
</if>
<if test="proobj_username != null">
AND protect_object_create_username = #{proobj_username}
</if>
<if test="proobj_audit_status != null">
AND protect_object_audit_status = #{proobj_audit_status}
</if>
</where>
LIMIT ${(page-1) * page_size}, #{page_size}
</select>
@@ -69,11 +96,39 @@
FROM t_protect_object
WHERE protect_object_id = #{proobj_id}
</select>
<select id="queryProtectObjectsTotalNum" resultType="java.lang.Integer">
SELECT COUNT(protect_object_id) FROM t_protect_object
<where>
<if test="proobj_name != null">protect_object_name LIKE CONCAT('%', #{proobj_name}, '%')</if>
<if test="proobj_id != null">protect_object_id = #{proobj_id}</if>
<if test="proobj_name != null">AND protect_object_name LIKE CONCAT('%', #{proobj_name}, '%')</if>
<if test="proobj_id != null">AND protect_object_id = #{proobj_id}</if>
<if test="proobj_system_name != null">
AND protect_object_system_name LIKE CONCAT('%', #{proobj_system_name}, '%')
</if>
<if test="proobj_ip != null">
AND protect_object_id IN (
SELECT protect_object_id FROM t_protect_object_inet_addr_view tpo_view
WHERE tpo_view.protect_object_ip LIKE CONCAT('%', #{proobj_ip}, '%')
)
</if>
<if test="proobj_port_min != null">
AND protect_object_port &gt;= #{proobj_port_min}
</if>
<if test="proobj_port_max != null">
AND protect_object_port &lt;= #{proobj_port_max}
</if>
<if test="proobj_url != null">
AND protect_object_url LIKE CONCAT('%', #{proobj_url}, '%')
</if>
<if test="proobj_protocol != null">
AND protect_object_protocol = #{proobj_protocol}
</if>
<if test="proobj_username != null">
AND protect_object_create_username = #{proobj_username}
</if>
<if test="proobj_audit_status != null">
AND protect_object_audit_status = #{proobj_audit_status}
</if>
</where>
</select>

View File

@@ -86,6 +86,12 @@
<select id="queryTemplates" resultMap="templateMap">
SELECT * FROM template_view
<where>
<if test="source_system != null">
AND strategy_template_source_system = #{source_system}
</if>
<if test="create_username != null">
AND strategy_template_create_username = #{create_username}
</if>
<if test="template_name != null">
AND strategy_template_name LIKE CONCAT('%', #{template_name}, '%')
</if>
@@ -108,6 +114,12 @@
<select id="queryTemplateTotalNum" resultType="java.lang.Integer">
SELECT COUNT(strategy_template_id) FROM t_strategy_template
<where>
<if test="source_system != null">
AND strategy_template_source_system = #{source_system}
</if>
<if test="create_username != null">
AND strategy_template_create_username = #{create_username}
</if>
<if test="template_name != null">
AND strategy_template_name LIKE CONCAT('%', #{template_name}, '%')
</if>

View File

@@ -71,18 +71,49 @@ class ProtectObjectServiceTest extends ProtectionApplicationTests {
protectObjects.forEach(protectObject -> {
assertNotNull(protectObjectService.queryProtectObject(protectObject.getProtectObjectId()));
assertNotNull(protectObjectService.queryProtectObjects(null,
protectObject.getProtectObjectId(), 1, 1));
assertNotNull(protectObjectService.queryProtectObjects(
null,
protectObject.getProtectObjectId(),
protectObject.getProtectObjectSystemName(),
protectObject.getProtectObjectIPAddress(),
protectObject.getProtectObjectPort(),
protectObject.getProtectObjectPort(),
protectObject.getProtectObjectURL(),
protectObject.getProtectObjectProtocol(),
protectObject.getProtectObjectCreateUsername(),
protectObject.getProtectObjectAuditStatus(),
1, 1));
});
assertEquals(100,
protectObjectService.queryProtectObjects(testName, null, 1, 1000).size());
protectObjectService.queryProtectObjects(testName,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1, 100).size());
}
@Test
void updateProtectObject() {
List<ProtectObject> protectObjects = protectObjectService.queryProtectObjects(null, null, 1, 1);
List<ProtectObject> protectObjects = protectObjectService.queryProtectObjects(
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1, 1);
Integer testId = protectObjects.get(0).getProtectObjectId();
protectObject.setProtectObjectName("x-1-1");

View File

@@ -35,8 +35,12 @@ public class DynamicRuleServiceTest extends ProtectionApplicationTests {
@Test
void testNewDynamicRule() {
List<ProtectObject> protectObject = protectObjectService.queryProtectObjects(null, null, 1, 1);
List<Template> templates = templateService.queryTemplates(null, 1, 1);
List<ProtectObject> protectObject = protectObjectService.queryProtectObjects(
null, null, null,null,
null,null,null,null,
null,null, 1, 1);
List<Template> templates = templateService.queryTemplates(
null, null, null, 1, 1);
DynamicRuleObject object = new DynamicRuleObject();
object.setDynamicRuleName("UpdateDynamicRule2");
@@ -52,8 +56,20 @@ public class DynamicRuleServiceTest extends ProtectionApplicationTests {
@Test
void testDeleteDynamicRule() {
List<ProtectObject> protectObject = protectObjectService.queryProtectObjects(null, null, 1, 1);
List<Template> templates = templateService.queryTemplates(null, 1, 1);
List<ProtectObject> protectObject = protectObjectService.queryProtectObjects(
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1, 1);
List<Template> templates = templateService.queryTemplates(
null, null,null, 1, 1);
DynamicRuleObject object = new DynamicRuleObject();
object.setDynamicRuleName("UpdateDynamicRule2");