This is an automated email from the ASF dual-hosted git repository.

xxyu pushed a commit to branch kylin5
in repository https://gitbox.apache.org/repos/asf/kylin.git

commit 9006fc9236e064578626228112eaa00a80d56c4d
Author: binbin.zheng <binbin.zh...@kyligence.io>
AuthorDate: Fri Nov 18 20:38:32 2022 +0800

    KYLIN-5427 fix null password exception message
---
 .../main/resources/kylin_error_msg_conf_en.properties   |  2 +-
 .../apache/kylin/rest/controller/NUserController.java   | 17 +++++++----------
 .../kylin/rest/controller/NUserControllerTest.java      | 11 +++++++++++
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git 
a/src/core-common/src/main/resources/kylin_error_msg_conf_en.properties 
b/src/core-common/src/main/resources/kylin_error_msg_conf_en.properties
index 0720984e8e..f8a170e52e 100644
--- a/src/core-common/src/main/resources/kylin_error_msg_conf_en.properties
+++ b/src/core-common/src/main/resources/kylin_error_msg_conf_en.properties
@@ -109,7 +109,7 @@ KE-010012202=Can't add this index, as the same index 
already exists. Please modi
 KE-010012203=The parameter "%s" only supports "%s".
 
 ## 10043XX parameter check
-KE-010043201=Request parameter "%s" is empty or value is empty. Please check 
the request parameters are filled in correctly.
+KE-010043201=Request parameter "%s" is empty or value is empty. Please check 
the request parameters.
 KE-010043202=The entered parameter value is invalid. The timestamp of the 
start time and end time conversion must be greater than or equal to 0. Please 
check and try again.
 KE-010043203=The entered parameter value is invalid. The end time must be 
greater than the start time. Please check and try again.
 KE-010043204=The entered parameter value is invalid. The end time must be 
greater than or equal to the start time. Please check and try again.
diff --git 
a/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NUserController.java
 
b/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NUserController.java
index 37b64a1917..60b4e0797a 100644
--- 
a/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NUserController.java
+++ 
b/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NUserController.java
@@ -174,18 +174,15 @@ public class NUserController extends NBasicController 
implements ApplicationList
     //do not use aclEvaluate, if there's no users and will come into init() 
and will call save.
     public EnvelopeResponse<String> createUser(@RequestBody UserRequest user) 
throws IOException {
         checkRequiredArg("disabled", user.getDisabled());
+        checkUsername(user.getUsername());
+        checkRequiredArg("password", user.getPassword());
+        val decodedPassword = pwdBase64Decode(user.getPassword());
+        checkPasswordLength(decodedPassword);
+        checkPasswordCharacter(decodedPassword);
+        user.setPassword(decodedPassword);
         val simpleGrantedAuthorities = 
user.transformSimpleGrantedAuthorities();
-        val username = user.getUsername();
-        val password = pwdBase64Decode(user.getPassword());
-        user.setPassword(password);
-
-        checkUsername(username);
-        checkPasswordLength(password);
-        checkPasswordCharacter(password);
         checkUserGroupNotEmpty(simpleGrantedAuthorities);
-
-        List<String> allGroups = userGroupService.getAllUserGroups();
-        checkUserGroupExists(simpleGrantedAuthorities, allGroups);
+        checkUserGroupExists(simpleGrantedAuthorities, 
userGroupService.getAllUserGroups());
         checkUserGroupNotDuplicated(simpleGrantedAuthorities);
         return createAdminUser(user.updateManager(new ManagedUser()));
     }
diff --git 
a/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/NUserControllerTest.java
 
b/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/NUserControllerTest.java
index 74a4f4b467..49359f2f18 100644
--- 
a/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/NUserControllerTest.java
+++ 
b/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/NUserControllerTest.java
@@ -278,6 +278,17 @@ public class NUserControllerTest extends 
NLocalFileMetadataTestCase {
         nUserController.createUser(user);
     }
 
+    @Test
+    public void testCreateUserWithNullPassword() throws IOException {
+        UserRequest userRequest = new UserRequest();
+        userRequest.setDisabled(false);
+        userRequest.setUsername("123");
+        userRequest.setPassword(null);
+        thrown.expect(KylinException.class);
+        
thrown.expectMessage(REQUEST_PARAMETER_EMPTY_OR_VALUE_EMPTY.getMsg("password"));
+        nUserController.createUser(userRequest);
+    }
+
     @Test
     public void testCreateUser_PasswordLength_Exception() throws Exception {
         val user = new UserRequest();

Reply via email to