You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2021/09/17 10:15:00 UTC

[servicecomb-java-chassis] branch master updated: #2585 Make the user name not decrypted (#2586)

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

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new a1ad474  #2585 Make the user name not decrypted (#2586)
a1ad474 is described below

commit a1ad4747b8020dc3a92c67a39748e1afead22fe1
Author: zyl <72...@users.noreply.github.com>
AuthorDate: Fri Sep 17 18:14:56 2021 +0800

    #2585 Make the user name not decrypted (#2586)
---
 .../serviceregistry/auth/TokenCacheManager.java    |  2 +-
 .../auth/TokenCacheManagerTest.java                | 40 ++++++++++++++++++++++
 .../src/test/resources/microservice.yaml           |  6 ++++
 3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/auth/TokenCacheManager.java b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/auth/TokenCacheManager.java
index 96e129b..0c20fc5 100644
--- a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/auth/TokenCacheManager.java
+++ b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/auth/TokenCacheManager.java
@@ -151,7 +151,7 @@ public final class TokenCacheManager {
       ServiceCenterClient serviceCenterClient = serviceCenterClients.get(this.registryName);
 
       RbacTokenRequest request = new RbacTokenRequest();
-      request.setName(new String(cipher.decrypt(accountName.toCharArray())));
+      request.setName(accountName);
       request.setPassword(new String(cipher.decrypt(password.toCharArray())));
 
       RbacTokenResponse rbacTokenResponse = serviceCenterClient.queryToken(request);
diff --git a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/auth/TokenCacheManagerTest.java b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/auth/TokenCacheManagerTest.java
new file mode 100644
index 0000000..50c9821
--- /dev/null
+++ b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/auth/TokenCacheManagerTest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.serviceregistry.auth;
+
+import org.apache.servicecomb.foundation.auth.Cipher;
+import org.apache.servicecomb.service.center.client.model.RbacTokenRequest;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TokenCacheManagerTest {
+  RBACBootStrapService rbacBootStrapService = new RBACBootStrapService();
+
+  @Test
+  public void testCreateHeaders() {
+    Cipher cipher = rbacBootStrapService.getCipher("testCipher");
+    Assert.assertSame(cipher.name(), "testCipher");
+
+    RbacTokenRequest request = new RbacTokenRequest();
+    request.setName("root");
+    Assert.assertEquals(request.getName(), "root");
+
+    request.setPassword(new String(cipher.decrypt("testtest".toCharArray())));
+    Assert.assertEquals(request.getPassword(), "test");
+  }
+}
\ No newline at end of file
diff --git a/service-registry/registry-service-center/src/test/resources/microservice.yaml b/service-registry/registry-service-center/src/test/resources/microservice.yaml
index 3d9818a..7b10820 100644
--- a/service-registry/registry-service-center/src/test/resources/microservice.yaml
+++ b/service-registry/registry-service-center/src/test/resources/microservice.yaml
@@ -55,6 +55,12 @@ servicecomb:
     name: myDC
     region: my-Region
     availableZone: my-Zone
+  credentials:
+    rbac.enabled: false
+    account:
+      name: root
+      password: testtest
+    cipher: testCipher
 #ssl.keystore.path=
 #ssl.keystore.pass=
 #ssl.truststore.path=