From cdde1d68cf1a3f00c72a0d5125e11cd1477e7468 Mon Sep 17 00:00:00 2001 From: "saimu.msm" Date: Fri, 31 May 2024 10:26:26 +0800 Subject: [PATCH] fix subscribe webhook --- .../AlarmSubscribeFacadeImplChecker.java | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/security/custom/AlarmSubscribeFacadeImplChecker.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/security/custom/AlarmSubscribeFacadeImplChecker.java index 6cf4d0e41..b0f493e0d 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/security/custom/AlarmSubscribeFacadeImplChecker.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/security/custom/AlarmSubscribeFacadeImplChecker.java @@ -10,12 +10,14 @@ import io.holoinsight.server.common.dao.entity.AlarmGroup; import io.holoinsight.server.common.dao.entity.AlarmRule; import io.holoinsight.server.common.dao.entity.AlarmSubscribe; +import io.holoinsight.server.common.dao.entity.AlarmWebhook; import io.holoinsight.server.common.dao.entity.dto.AlarmSubscribeDTO; import io.holoinsight.server.common.dao.entity.dto.AlarmSubscribeInfo; import io.holoinsight.server.common.dao.mapper.AlarmDingDingRobotMapper; import io.holoinsight.server.common.dao.mapper.AlarmGroupMapper; import io.holoinsight.server.common.dao.mapper.AlarmRuleMapper; import io.holoinsight.server.common.dao.mapper.AlarmSubscribeMapper; +import io.holoinsight.server.common.dao.mapper.AlarmWebhookMapper; import io.holoinsight.server.common.scope.MonitorUser; import io.holoinsight.server.common.service.RequestContextAdapter; import io.holoinsight.server.home.web.security.LevelAuthorizationCheck; @@ -59,6 +61,8 @@ public class AlarmSubscribeFacadeImplChecker private AlarmRuleMapper alarmRuleMapper; @Resource private AlarmDingDingRobotMapper dingDingRobotMapper; + @Resource + private AlarmWebhookMapper webhookMapper; private static final Set Notice_Type_Set = new HashSet<>(Arrays.asList("dingding", "sms", "phone", "email", "dingDingRobot")); @@ -172,11 +176,18 @@ private LevelAuthorizationCheckResult checkAlarmSubscribeDTO(String methodName, } if (alarmSubscribeInfo.getGroupId() != null && alarmSubscribeInfo.getGroupId() > 0) { - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("id", alarmSubscribeInfo.getGroupId()); - requestContextAdapter.queryWrapperTenantAdapt(queryWrapper, tenant, simpleWorkspace); - List existedAlarmGroups = this.alarmGroupMapper.selectList(queryWrapper); - if (CollectionUtils.isEmpty(existedAlarmGroups)) { + boolean validGroupId; + if (isWebhookNoticeType(alarmSubscribeInfo.getNoticeType())) { + validGroupId = checkWebhook(alarmSubscribeInfo.getGroupId(), tenant); + } else { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("id", alarmSubscribeInfo.getGroupId()); + requestContextAdapter.queryWrapperTenantAdapt(queryWrapper, tenant, simpleWorkspace); + List existedAlarmGroups = this.alarmGroupMapper.selectList(queryWrapper); + validGroupId = !CollectionUtils.isEmpty(existedAlarmGroups); + } + + if (!validGroupId) { return failCheckResult("invalid AlarmGroup id %s, for tenant %s, workspace %s", alarmSubscribeInfo.getGroupId(), tenant, simpleWorkspace); } @@ -198,6 +209,23 @@ private LevelAuthorizationCheckResult checkAlarmSubscribeDTO(String methodName, return successCheckResult(); } + private boolean checkWebhook(Long groupId, String tenant) { + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("id", groupId); + this.requestContextAdapter.queryWrapperTenantAdapt(queryWrapper, tenant); + + List webhooks = this.webhookMapper.selectList(queryWrapper); + return !CollectionUtils.isEmpty(webhooks); + } + + private boolean isWebhookNoticeType(List noticeType) { + if (CollectionUtils.isEmpty(noticeType)) { + return false; + } + return noticeType.contains("webhook"); + } + private boolean checkDingRobotSubscriber(String dingRobotId, String tenant, String simpleWorkspace) { if (StringUtils.isEmpty(dingRobotId) || !StringUtils.isNumeric(dingRobotId)) {