From d16e0ddb2f1c68fccc5cf41481d769c2a1012379 Mon Sep 17 00:00:00 2001 From: syyangs799 <55483518+syyangs799@users.noreply.github.com> Date: Wed, 15 Jun 2022 18:44:26 +0800 Subject: [PATCH] [Bug-10394] [Update Possword] Change password shows error (#10437) * Add a status code for password verification length to improve user interaction * Modify the length and null value, verify them separately and return * Modify the length and null value, verify them separately and return * remove the outer not empty validate and Modify judgment conditions * add the outer not empty validate and remove inter empty Co-authored-by: syyang <730122+syyang99@user.noreply.gitee.com> --- .../apache/dolphinscheduler/api/enums/Status.java | 1 + .../api/service/impl/UsersServiceImpl.java | 5 +++-- .../dolphinscheduler/api/utils/CheckUtils.java | 14 +++++++++++++- .../dolphinscheduler/api/utils/CheckUtilsTest.java | 3 +++ .../apache/dolphinscheduler/common/Constants.java | 6 ++++++ 5 files changed, 26 insertions(+), 3 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 80e2b2c999..a04d994440 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 @@ -422,6 +422,7 @@ public enum Status { 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", "资源文件名过长"), TENANT_FULL_NAME_TOO_LONG_ERROR(1300016, "tenant's fullname is too long error", "租户名过长"), + USER_PASSWORD_LENGTH_ERROR(1300017, "user's password length error", "用户密码长度错误"), NO_CURRENT_OPERATING_PERMISSION(1400001, "The current user does not have this permission.", "当前用户无此权限"), FUNCTION_DISABLED(1400002, "The current feature is disabled.", "当前功能已被禁用"), diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java index 34cbc91869..33e99f4651 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java @@ -80,6 +80,7 @@ import java.util.Arrays; import java.util.stream.Collectors; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.USER_MANAGER; +import static org.apache.dolphinscheduler.common.Constants.USER_PASSWORD_MAX_LENGTH; /** * users service impl @@ -414,8 +415,8 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService { } if (StringUtils.isNotEmpty(userPassword)) { - if (!CheckUtils.checkPassword(userPassword)) { - putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, userPassword); + if (!CheckUtils.checkPasswordLength(userPassword)) { + putMsg(result, Status.USER_PASSWORD_LENGTH_ERROR); return result; } user.setUserPassword(EncryptionUtils.getMd5(userPassword)); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java index f1f9d73d1d..33dd23113f 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java @@ -31,6 +31,9 @@ import java.util.regex.Pattern; import org.hibernate.validator.internal.constraintvalidators.bv.EmailValidator; +import static org.apache.dolphinscheduler.common.Constants.USER_PASSWORD_MAX_LENGTH; +import static org.apache.dolphinscheduler.common.Constants.USER_PASSWORD_MIN_LENGTH; + /** * check utils */ @@ -105,7 +108,16 @@ public class CheckUtils { * @return true if password regex valid, otherwise return false */ public static boolean checkPassword(String password) { - return !StringUtils.isEmpty(password) && password.length() >= 2 && password.length() <= 20; + return !StringUtils.isEmpty(password) && checkPasswordLength(password); + } + + /** + * check password length + * @param password password + * @return true if password length valid, otherwise return false + */ + public static boolean checkPasswordLength(String password) { + return password.length() >= USER_PASSWORD_MIN_LENGTH && password.length() <= USER_PASSWORD_MAX_LENGTH; } /** diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/CheckUtilsTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/CheckUtilsTest.java index 1f1fdb0571..a3a414dab9 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/CheckUtilsTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/CheckUtilsTest.java @@ -79,6 +79,9 @@ public class CheckUtilsTest { assertFalse(CheckUtils.checkPassword("a")); assertFalse(CheckUtils.checkPassword("1234567890abcderfasdf2")); assertTrue(CheckUtils.checkPassword("123456")); + assertFalse(CheckUtils.checkPasswordLength("1")); + assertTrue(CheckUtils.checkPasswordLength("dolphinscheduler123")); + assertFalse(CheckUtils.checkPasswordLength("dolphinscheduler123456")); } /** 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 90820f6d40..2c37b98ecc 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 @@ -820,4 +820,10 @@ public final class Constants { */ public static final int SCHEDULE_TIME_MAX_LENGTH = 100; + /** + * password max and min LENGTH + */ + public static final int USER_PASSWORD_MAX_LENGTH = 20; + + public static final int USER_PASSWORD_MIN_LENGTH = 2; }