From 4f11be7126bf1fa6f2eee2a9ccfde6bfde0b1dc6 Mon Sep 17 00:00:00 2001 From: hstdream <33045461+hstdream@users.noreply.github.com> Date: Wed, 18 May 2022 01:36:40 +0800 Subject: [PATCH] [Fix-10080]When the created tenant name is too long, an error message will be prompted (#10081) * [Fix-10080]When the created tenant name is too long, an error message will be prompted * [Fix-10080]When the created tenant name is too long, an error message will be prompted * [Fix-10080]When the created tenant name is too long, an error message will be prompted Co-authored-by: houshitao (cherry picked from commit 67cf7b280087d4424bf0c2a698c9c12ab874bd2e) --- .../org/apache/dolphinscheduler/api/enums/Status.java | 3 ++- .../api/service/impl/TenantServiceImpl.java | 9 ++++++++- .../org/apache/dolphinscheduler/common/Constants.java | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index a755a75e1c..b315c313cb 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -401,7 +401,8 @@ public enum Status { QUERY_UNAUTHORIZED_NAMESPACE_ERROR(1300012, "query unauthorized namespace error", "查询未授权命名空间错误"), QUERY_AUTHORIZED_NAMESPACE_ERROR(1300013, "query authorized namespace error", "查询授权命名空间错误"), QUERY_CAN_USE_K8S_CLUSTER_ERROR(1300014, "login user query can used k8s cluster list error", "查询可用k8s集群错误"), - RESOURCE_FULL_NAME_TOO_LONG_ERROR(1300015, "resource's fullname is too long error", "资源文件名过长"); + RESOURCE_FULL_NAME_TOO_LONG_ERROR(1300015, "resource's fullname is too long error", "资源文件名过长"), + TENANT_FULL_NAME_TOO_LONG_ERROR(1300016, "tenant's fullname is too long error", "租户名过长"); private final int code; private final String enMsg; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java index fb92c1583d..6bb2870452 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java @@ -40,12 +40,13 @@ import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.apache.dolphinscheduler.common.Constants.TENANT_FULL_NAME_MAX_LENGTH; + /** * tenant service impl */ @@ -89,11 +90,17 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService return result; } + if(StringUtils.length(tenantCode) > TENANT_FULL_NAME_MAX_LENGTH){ + putMsg(result, Status.TENANT_FULL_NAME_TOO_LONG_ERROR); + return result; + } + if (!RegexUtils.isValidLinuxUserName(tenantCode)) { putMsg(result, Status.CHECK_OS_TENANT_CODE_ERROR); return result; } + if (checkTenantExists(tenantCode)) { putMsg(result, Status.OS_TENANT_CODE_EXIST, tenantCode); return result; diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java index d1d240f28c..57b5c92970 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java @@ -823,4 +823,9 @@ public final class Constants { */ public static final String SCHEDULE_TIMEZONE = "schedule_timezone"; public static final int RESOURCE_FULL_NAME_MAX_LENGTH = 128; + + /** + * tenant + */ + public static final int TENANT_FULL_NAME_MAX_LENGTH = 30; }