Commit 5adf07b766ba0256531273883ea710dcfeee17c8

Authored by YunaiV
1 parent 566f5a12

feat: add validation for website parameter in TenantController and AppTenantController

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,7 +20,9 @@ import jakarta.annotation.Resource;
20 import jakarta.annotation.security.PermitAll; 20 import jakarta.annotation.security.PermitAll;
21 import jakarta.servlet.http.HttpServletResponse; 21 import jakarta.servlet.http.HttpServletResponse;
22 import jakarta.validation.Valid; 22 import jakarta.validation.Valid;
  23 +import jakarta.validation.constraints.Pattern;
23 import org.springframework.security.access.prepost.PreAuthorize; 24 import org.springframework.security.access.prepost.PreAuthorize;
  25 +import org.springframework.validation.annotation.Validated;
24 import org.springframework.web.bind.annotation.*; 26 import org.springframework.web.bind.annotation.*;
25 27
26 import java.io.IOException; 28 import java.io.IOException;
@@ -33,6 +35,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. @@ -33,6 +35,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
33 @Tag(name = "管理后台 - 租户") 35 @Tag(name = "管理后台 - 租户")
34 @RestController 36 @RestController
35 @RequestMapping("/system/tenant") 37 @RequestMapping("/system/tenant")
  38 +@Validated
36 public class TenantController { 39 public class TenantController {
37 40
38 @Resource 41 @Resource
@@ -63,7 +66,8 @@ public class TenantController { @@ -63,7 +66,8 @@ public class TenantController {
63 @TenantIgnore 66 @TenantIgnore
64 @Operation(summary = "使用域名,获得租户信息", description = "登录界面,根据用户的域名,获得租户信息") 67 @Operation(summary = "使用域名,获得租户信息", description = "登录界面,根据用户的域名,获得租户信息")
65 @Parameter(name = "website", description = "域名", required = true, example = "www.iocoder.cn") 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 TenantDO tenant = tenantService.getTenantByWebsite(website); 71 TenantDO tenant = tenantService.getTenantByWebsite(website);
68 if (tenant == null || CommonStatusEnum.isDisable(tenant.getStatus())) { 72 if (tenant == null || CommonStatusEnum.isDisable(tenant.getStatus())) {
69 return success(null); 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,6 +12,8 @@ import io.swagger.v3.oas.annotations.Parameter;
12 import io.swagger.v3.oas.annotations.tags.Tag; 12 import io.swagger.v3.oas.annotations.tags.Tag;
13 import jakarta.annotation.Resource; 13 import jakarta.annotation.Resource;
14 import jakarta.annotation.security.PermitAll; 14 import jakarta.annotation.security.PermitAll;
  15 +import jakarta.validation.constraints.Pattern;
  16 +import org.springframework.validation.annotation.Validated;
15 import org.springframework.web.bind.annotation.GetMapping; 17 import org.springframework.web.bind.annotation.GetMapping;
16 import org.springframework.web.bind.annotation.RequestMapping; 18 import org.springframework.web.bind.annotation.RequestMapping;
17 import org.springframework.web.bind.annotation.RequestParam; 19 import org.springframework.web.bind.annotation.RequestParam;
@@ -22,6 +24,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -22,6 +24,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
22 @Tag(name = "用户 App - 租户") 24 @Tag(name = "用户 App - 租户")
23 @RestController 25 @RestController
24 @RequestMapping("/system/tenant") 26 @RequestMapping("/system/tenant")
  27 +@Validated
25 public class AppTenantController { 28 public class AppTenantController {
26 29
27 @Resource 30 @Resource
@@ -32,7 +35,8 @@ public class AppTenantController { @@ -32,7 +35,8 @@ public class AppTenantController {
32 @TenantIgnore 35 @TenantIgnore
33 @Operation(summary = "使用域名,获得租户信息", description = "根据用户的域名,获得租户信息") 36 @Operation(summary = "使用域名,获得租户信息", description = "根据用户的域名,获得租户信息")
34 @Parameter(name = "website", description = "域名", required = true, example = "www.iocoder.cn") 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 TenantDO tenant = tenantService.getTenantByWebsite(website); 40 TenantDO tenant = tenantService.getTenantByWebsite(website);
37 if (tenant == null || CommonStatusEnum.isDisable(tenant.getStatus())) { 41 if (tenant == null || CommonStatusEnum.isDisable(tenant.getStatus())) {
38 return success(null); 42 return success(null);