Skip to content

Commit

Permalink
feat: alarm subscribe checker (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
masaimu authored May 28, 2024
1 parent 4caac05 commit f228c2e
Show file tree
Hide file tree
Showing 6 changed files with 316 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package io.holoinsight.server.common;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

Expand All @@ -18,6 +19,7 @@
*/
@EqualsAndHashCode
@ToString
@Data
public class Pair<L, R> implements Serializable {

private static final long serialVersionUID = -1292525629741844984L;
Expand Down Expand Up @@ -60,5 +62,4 @@ public L left() {
public R right() {
return right;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.holoinsight.server.common.ResultCodeEnum;
import io.holoinsight.server.common.dao.entity.AlarmSubscribe;
import io.holoinsight.server.common.dao.entity.dto.AlarmSubscribeInfo;
import io.holoinsight.server.home.web.security.LevelAuthorizationAccess;
import io.holoinsight.server.home.web.security.ParameterSecurityService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -60,15 +61,15 @@ public class AlarmSubscribeFacadeImpl extends BaseFacade {
@Autowired
private ParameterSecurityService parameterSecurityService;

@LevelAuthorizationAccess(paramConfigs = {"PARAMETER" + ":$!uniqueId"},
levelAuthorizationCheckeClass = "io.holoinsight.server.home.web.security.custom.AlarmSubscribeFacadeImplChecker")
@GetMapping(value = "/queryByUniqueId/{uniqueId}")
@MonitorScopeAuth(targetType = AuthTargetType.TENANT, needPower = PowerConstants.VIEW)
public JsonResult<AlarmSubscribeDTO> queryByUniqueId(@PathVariable("uniqueId") String uniqueId) {
final JsonResult<AlarmSubscribeDTO> result = new JsonResult<>();
facadeTemplate.manage(result, new ManageCallback() {
@Override
public void checkParameter() {
ParaCheckUtil.checkParaNotBlank(uniqueId, "uniqueId");
}
public void checkParameter() {}

@Override
public void doManage() {
Expand All @@ -84,6 +85,8 @@ public void doManage() {
return result;
}

@LevelAuthorizationAccess(paramConfigs = {"PARAMETER" + ":$!alarmSubscribeDTO"},
levelAuthorizationCheckeClass = "io.holoinsight.server.home.web.security.custom.AlarmSubscribeFacadeImplChecker")
@PostMapping("/submit")
@ResponseBody
@MonitorScopeAuth(targetType = AuthTargetType.TENANT, needPower = PowerConstants.EDIT)
Expand All @@ -102,50 +105,7 @@ public JsonResult<Boolean> saveBatch(AlarmSubscribeDTO alarmSubscribeDTO) {
final JsonResult<Boolean> result = new JsonResult<>();
facadeTemplate.manage(result, new ManageCallback() {
@Override
public void checkParameter() {
ParaCheckUtil.checkParaNotNull(alarmSubscribeDTO, "alarmSubscribeDTO");
MonitorScope ms = RequestContext.getContext().ms;
MonitorUser mu = RequestContext.getContext().mu;
String uniqueId = alarmSubscribeDTO.getUniqueId();
if (StringUtils.isNotEmpty(uniqueId)) {
ParaCheckUtil.checkParaBoolean(
parameterSecurityService.checkRuleTenantAndWorkspace(uniqueId, tenant(), workspace()),
"uniqueId do not belong to this tenant " + tenant() + " or workspace " + workspace());
}
if (!CollectionUtils.isEmpty(alarmSubscribeDTO.getAlarmSubscribe())) {
for (AlarmSubscribeInfo alarmSubscribeInfo : alarmSubscribeDTO.getAlarmSubscribe()) {
if (StringUtils.isNotEmpty(alarmSubscribeInfo.getUniqueId())) {
ParaCheckUtil.checkParaBoolean(
parameterSecurityService.checkRuleTenantAndWorkspace(
alarmSubscribeInfo.getUniqueId(), tenant(), workspace()),
"uniqueId do not belong to this tenant " + tenant() + " or workspace "
+ workspace());
}
if (CollectionUtils.isEmpty(alarmSubscribeInfo.getNoticeType())) {
continue;
}
if (alarmSubscribeInfo.getNoticeType().contains("dingding")
|| alarmSubscribeInfo.getNoticeType().contains("sms")
|| alarmSubscribeInfo.getNoticeType().contains("phone")
|| alarmSubscribeInfo.getNoticeType().contains("email")) {
ParaCheckUtil.checkParaBoolean(parameterSecurityService.checkUserTenantAndWorkspace(
alarmSubscribeInfo.getSubscriber(), mu), "invalid subscriber");
}
if (alarmSubscribeInfo.getNoticeType().contains("dingDingRobot")) {
ParaCheckUtil.checkParaBoolean(parameterSecurityService.checkGroupTenantAndWorkspace(
alarmSubscribeInfo.getGroupId(), ms.getTenant(),
requestContextAdapter.getWorkspace(true)), "invalid subscriber");
}

if (null != alarmSubscribeInfo.getId()) {
AlarmSubscribe byId = alarmSubscribeService.getById(alarmSubscribeInfo.getId());
if (null == byId) {
throw new MonitorException(ResultCodeEnum.CANNOT_FIND_RECORD, "id not existed");
}
}
}
}
}
public void checkParameter() {}

@Override
public void doManage() {
Expand All @@ -163,15 +123,15 @@ public void doManage() {
return result;
}

@LevelAuthorizationAccess(paramConfigs = {"PARAMETER" + ":$!uniqueId"},
levelAuthorizationCheckeClass = "io.holoinsight.server.home.web.security.custom.AlarmSubscribeFacadeImplChecker")
@GetMapping(value = "/querySubUsers/{uniqueId}")
@MonitorScopeAuth(targetType = AuthTargetType.TENANT, needPower = PowerConstants.VIEW)
public JsonResult<List<MonitorUser>> querySubUsers(@PathVariable("uniqueId") String uniqueId) {
final JsonResult<List<MonitorUser>> result = new JsonResult<>();
facadeTemplate.manage(result, new ManageCallback() {
@Override
public void checkParameter() {
ParaCheckUtil.checkParaNotBlank(uniqueId, "uniqueId");
}
public void checkParameter() {}

@Override
public void doManage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ boolean checkFilterTenantAndWorkspace(String metricTable, Map<String, List<Objec
List<String> getDetailFilters(DataQueryRequest request);

boolean checkRelateId(String relateId, String relateType, String tenant, String workspace);

boolean checkTenant(String target, String tenant);
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ public boolean checkRelateId(String relateId, String relateType, String tenant,
String workspace) {
return true;
}

@Override
public boolean checkTenant(String target, String tenant) {
return StringUtils.equals(target, tenant);
}
}
Loading

0 comments on commit f228c2e

Please sign in to comment.