diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java index 58c29df21bb..a4acc9a9321 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java @@ -69,7 +69,7 @@ public class AppServiceImpl implements AppService, CommandLineRunner { @Override public List getAppParamDefines(String app) { - if (app == null) { + if (app == null || app.chars().allMatch(Character::isSpaceChar)) { return Collections.emptyList(); } Job appDefine = appDefines.get(app.toLowerCase()); @@ -82,7 +82,7 @@ public List getAppParamDefines(String app) { @Override public Job getAppDefine(String app) throws IllegalArgumentException { - if (app == null) { + if (app == null || app.chars().allMatch(Character::isSpaceChar)) { throw new IllegalArgumentException("The app can not null."); } Job appDefine = appDefines.get(app.toLowerCase()); diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MonitorServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MonitorServiceImpl.java index edddea74d56..6176f9fe43a 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MonitorServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MonitorServiceImpl.java @@ -25,11 +25,7 @@ import org.dromara.hertzbeat.common.entity.job.Metrics; import org.dromara.hertzbeat.common.entity.manager.Tag; import org.dromara.hertzbeat.common.entity.message.CollectRep; -import org.dromara.hertzbeat.common.util.AesUtil; -import org.dromara.hertzbeat.common.util.CommonConstants; -import org.dromara.hertzbeat.common.util.IntervalExpressionUtil; -import org.dromara.hertzbeat.common.util.IpDomainUtil; -import org.dromara.hertzbeat.common.util.SnowFlakeIdGenerator; +import org.dromara.hertzbeat.common.util.*; import org.dromara.hertzbeat.manager.dao.MonitorDao; import org.dromara.hertzbeat.manager.dao.ParamDao; import org.dromara.hertzbeat.manager.pojo.dto.AppCount; @@ -50,6 +46,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import org.springframework.util.InvalidMimeTypeException; import java.time.LocalDateTime; import java.util.*; @@ -332,10 +329,28 @@ public void validate(MonitorDto monitorDto, Boolean isModify) throws IllegalArgu } break; case "checkbox": - // todo checkbox校验 + List checkboxOptions = paramDefine.getOptions(); + boolean checkboxInvalid = true; + if (checkboxOptions != null) { + for (ParamDefine.Option option : checkboxOptions) { + if (param.getValue().equalsIgnoreCase(option.getValue())) { + checkboxInvalid = false; + break; + } + } + } + if (checkboxInvalid){ + throw new IllegalArgumentException("Params field " + field + " value " + + param.getValue() + " is invalid checkbox value"); + } break; case "key-value": - // todo key-value校验 + try{ + GsonUtil.toJson(param.getValue()); + } catch (Exception e){ + throw new IllegalArgumentException("Params field " + field + " value " + + param.getValue() + " is invalid key-value value"); + } break; // todo More parameter definitions and actual value format verification // 更多参数定义与实际值格式校验