You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by do...@apache.org on 2022/07/11 09:46:57 UTC

[inlong] branch master updated: [INLONG-4965][Manager] Fix np exception on user query api (#4971)

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

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new d9bd740c1 [INLONG-4965][Manager] Fix np exception on user query api (#4971)
d9bd740c1 is described below

commit d9bd740c13ff510d97d62446a1e55da2b0e12f35
Author: woofyzhao <49...@qq.com>
AuthorDate: Mon Jul 11 17:46:51 2022 +0800

    [INLONG-4965][Manager] Fix np exception on user query api (#4971)
---
 .../manager/service/core/impl/UserServiceImpl.java | 27 ++++++++++++----------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/UserServiceImpl.java b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/UserServiceImpl.java
index 99c78b779..dcb90fa12 100644
--- a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/UserServiceImpl.java
+++ b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/UserServiceImpl.java
@@ -22,6 +22,7 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.inlong.manager.common.enums.UserTypeEnum;
 import org.apache.inlong.manager.common.exceptions.BusinessException;
 import org.apache.inlong.manager.common.pojo.user.PasswordChangeRequest;
@@ -78,18 +79,20 @@ public class UserServiceImpl implements UserService {
         result.setValidDays(DateUtils.getValidDays(entity.getCreateTime(), entity.getDueDate()));
         result.setType(entity.getAccountType());
 
-        try {
-            // decipher according to stored key version
-            // note that if the version is null then the string is treated as unencrypted plain text
-            Integer version = entity.getEncryptVersion();
-            byte[] secretKeyBytes = AESUtils.decryptAsString(entity.getSecretKey(), version);
-            byte[] publicKeyBytes = AESUtils.decryptAsString(entity.getPublicKey(), version);
-            result.setSecretKey(new String(secretKeyBytes, StandardCharsets.UTF_8));
-            result.setPublicKey(new String(publicKeyBytes, StandardCharsets.UTF_8));
-        } catch (Exception e) {
-            String errMsg = String.format("decryption error: %s", e.getMessage());
-            log.error(errMsg, e);
-            throw new BusinessException(errMsg);
+        if (StringUtils.isNotBlank(entity.getSecretKey()) && StringUtils.isNotBlank(entity.getPublicKey())) {
+            try {
+                // decipher according to stored key version
+                // note that if the version is null then the string is treated as unencrypted plain text
+                Integer version = entity.getEncryptVersion();
+                byte[] secretKeyBytes = AESUtils.decryptAsString(entity.getSecretKey(), version);
+                byte[] publicKeyBytes = AESUtils.decryptAsString(entity.getPublicKey(), version);
+                result.setSecretKey(new String(secretKeyBytes, StandardCharsets.UTF_8));
+                result.setPublicKey(new String(publicKeyBytes, StandardCharsets.UTF_8));
+            } catch (Exception e) {
+                String errMsg = String.format("decryption error: %s", e.getMessage());
+                log.error(errMsg, e);
+                throw new BusinessException(errMsg);
+            }
         }
 
         log.debug("success to get user info by id={}", userId);