Commit 20f06c5116f38051f5378d1ee8cc7f7a4f85ff2e
1 parent
64515386
fix(oa): 补充邮箱服务器主机名与 IP 地址校验
关联:https://t.zsxq.com/y1ggF
Showing
1 changed file
with
20 additions
and
0 deletions
yudao-module-oa/src/main/java/cn/iocoder/yudao/module/oa/controller/admin/mail/vo/provider/OaMailProviderSaveReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.oa.controller.admin.mail.vo.provider; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.lang.Validator; | |
| 4 | +import cn.hutool.core.util.StrUtil; | |
| 3 | 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 6 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 5 | 7 | import io.swagger.v3.oas.annotations.media.Schema; |
| ... | ... | @@ -69,6 +71,24 @@ public class OaMailProviderSaveReqVO { |
| 69 | 71 | return sslEnable == null || !sslEnable.equals(starttlsEnable); |
| 70 | 72 | } |
| 71 | 73 | |
| 74 | + /** | |
| 75 | + * 校验服务器主机名或 IP,不包含协议、路径和端口 | |
| 76 | + */ | |
| 77 | + @AssertTrue(message = "请输入有效的服务器域名或 IP 地址") | |
| 78 | + @JsonIgnore | |
| 79 | + public boolean isHostValid() { | |
| 80 | + if (StrUtil.isEmpty(host)) { | |
| 81 | + return true; | |
| 82 | + } | |
| 83 | + if (host.contains(":")) { | |
| 84 | + return Validator.isIpv6(host); | |
| 85 | + } | |
| 86 | + if (host.matches("\\d+(?:\\.\\d+){3}")) { | |
| 87 | + return host.matches("(?:25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)){3}"); | |
| 88 | + } | |
| 89 | + return host.matches("(?i)[a-z\\d](?:[a-z\\d-]{0,61}[a-z\\d])?(?:\\.[a-z\\d](?:[a-z\\d-]{0,61}[a-z\\d])?)*\\.?"); | |
| 90 | + } | |
| 91 | + | |
| 72 | 92 | } |
| 73 | 93 | |
| 74 | 94 | } | ... | ... |