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

monitoring param host with http head will not be error reported #1155

Merged
merged 8 commits into from
Aug 8, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@
*
*/
public class HostParamValidator implements ConstraintValidator<HostValid, String> {
public static final String HTTP = "http://";
public static final String HTTPS = "https://";
tomsun28 marked this conversation as resolved.
Show resolved Hide resolved
public static final String BLANK = "";
public static final String patternHttp = "(?i)http://";
public static final String patternHttps = "(?i)https://";

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
// 判断value是否满足ipv4 ipv5 域名 格式
if(value.toLowerCase().contains(HTTP)){
value = value.replaceAll(patternHttp,BLANK);
}
if(value.toLowerCase().contains(HTTPS)){
value = value.replace(patternHttps,BLANK);
}
tomsun28 marked this conversation as resolved.
Show resolved Hide resolved
tomsun28 marked this conversation as resolved.
Show resolved Hide resolved
return IpDomainUtil.validateIpDomain(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@Constraint(validatedBy = HostParamValidator.class)
public @interface HostValid {

String message() default "监控Host必须是ipv4,ipv6或域名";
String message() default "监控Host必须是ipv4,ipv6或域名,<br>EX:192.168.53.27 或者 http://192.168.53.27";
tomsun28 marked this conversation as resolved.
Show resolved Hide resolved

Class<?>[] groups() default {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
public class MonitorServiceImpl implements MonitorService {
private static final Long MONITOR_ID_TMP = 1000000000L;

public static final String HTTP = "http://";
public static final String HTTPS = "https://";
public static final String BLANK = "";
public static final String patternHttp = "(?i)http://";
public static final String patternHttps = "(?i)https://";
tomsun28 marked this conversation as resolved.
Show resolved Hide resolved

private static final Gson GSON = new Gson();

@Autowired
Expand Down Expand Up @@ -379,6 +385,12 @@ public void validate(MonitorDto monitorDto, Boolean isModify) throws IllegalArgu
break;
case "host":
String hostValue = param.getValue();
if(hostValue.toLowerCase().contains(HTTP)){
hostValue = hostValue.replaceAll(patternHttp,BLANK);
}
if(hostValue.toLowerCase().contains(HTTPS)){
hostValue = hostValue.replace(patternHttps,BLANK);
}
tomsun28 marked this conversation as resolved.
Show resolved Hide resolved
if (!IpDomainUtil.validateIpDomain(hostValue)) {
throw new IllegalArgumentException("Params field " + field + " value "
+ hostValue + " is invalid host value.");
Expand Down