Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: alarm subscribe checker #857

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading