Commit 5adf07b766ba0256531273883ea710dcfeee17c8
1 parent
566f5a12
feat: add validation for website parameter in TenantController and AppTenantController
Showing
2 changed files
with
10 additions
and
2 deletions
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantController.java
| ... | ... | @@ -20,7 +20,9 @@ import jakarta.annotation.Resource; |
| 20 | 20 | import jakarta.annotation.security.PermitAll; |
| 21 | 21 | import jakarta.servlet.http.HttpServletResponse; |
| 22 | 22 | import jakarta.validation.Valid; |
| 23 | +import jakarta.validation.constraints.Pattern; | |
| 23 | 24 | import org.springframework.security.access.prepost.PreAuthorize; |
| 25 | +import org.springframework.validation.annotation.Validated; | |
| 24 | 26 | import org.springframework.web.bind.annotation.*; |
| 25 | 27 | |
| 26 | 28 | import java.io.IOException; |
| ... | ... | @@ -33,6 +35,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. |
| 33 | 35 | @Tag(name = "管理后台 - 租户") |
| 34 | 36 | @RestController |
| 35 | 37 | @RequestMapping("/system/tenant") |
| 38 | +@Validated | |
| 36 | 39 | public class TenantController { |
| 37 | 40 | |
| 38 | 41 | @Resource |
| ... | ... | @@ -63,7 +66,8 @@ public class TenantController { |
| 63 | 66 | @TenantIgnore |
| 64 | 67 | @Operation(summary = "使用域名,获得租户信息", description = "登录界面,根据用户的域名,获得租户信息") |
| 65 | 68 | @Parameter(name = "website", description = "域名", required = true, example = "www.iocoder.cn") |
| 66 | - public CommonResult<TenantRespVO> getTenantByWebsite(@RequestParam("website") String website) { | |
| 69 | + public CommonResult<TenantRespVO> getTenantByWebsite( | |
| 70 | + @RequestParam("website") @Pattern(regexp = "^[a-zA-Z0-9.-]+$", message = "网站域名格式不正确") String website) { | |
| 67 | 71 | TenantDO tenant = tenantService.getTenantByWebsite(website); |
| 68 | 72 | if (tenant == null || CommonStatusEnum.isDisable(tenant.getStatus())) { |
| 69 | 73 | return success(null); | ... | ... |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/app/tenant/AppTenantController.java
| ... | ... | @@ -12,6 +12,8 @@ import io.swagger.v3.oas.annotations.Parameter; |
| 12 | 12 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 13 | 13 | import jakarta.annotation.Resource; |
| 14 | 14 | import jakarta.annotation.security.PermitAll; |
| 15 | +import jakarta.validation.constraints.Pattern; | |
| 16 | +import org.springframework.validation.annotation.Validated; | |
| 15 | 17 | import org.springframework.web.bind.annotation.GetMapping; |
| 16 | 18 | import org.springframework.web.bind.annotation.RequestMapping; |
| 17 | 19 | import org.springframework.web.bind.annotation.RequestParam; |
| ... | ... | @@ -22,6 +24,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 22 | 24 | @Tag(name = "用户 App - 租户") |
| 23 | 25 | @RestController |
| 24 | 26 | @RequestMapping("/system/tenant") |
| 27 | +@Validated | |
| 25 | 28 | public class AppTenantController { |
| 26 | 29 | |
| 27 | 30 | @Resource |
| ... | ... | @@ -32,7 +35,8 @@ public class AppTenantController { |
| 32 | 35 | @TenantIgnore |
| 33 | 36 | @Operation(summary = "使用域名,获得租户信息", description = "根据用户的域名,获得租户信息") |
| 34 | 37 | @Parameter(name = "website", description = "域名", required = true, example = "www.iocoder.cn") |
| 35 | - public CommonResult<AppTenantRespVO> getTenantByWebsite(@RequestParam("website") String website) { | |
| 38 | + public CommonResult<AppTenantRespVO> getTenantByWebsite( | |
| 39 | + @RequestParam("website") @Pattern(regexp = "^[a-zA-Z0-9.-]+$", message = "网站域名格式不正确") String website) { | |
| 36 | 40 | TenantDO tenant = tenantService.getTenantByWebsite(website); |
| 37 | 41 | if (tenant == null || CommonStatusEnum.isDisable(tenant.getStatus())) { |
| 38 | 42 | return success(null); | ... | ... |