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/03/26 07:01:45 UTC
[servicecomb-java-chassis] branch master updated: [SCB-2224]
BeanUtils.getBeanOfType return null when aksk enabled (#2317)
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 30d01bf [SCB-2224] BeanUtils.getBeanOfType return null when aksk enabled (#2317)
30d01bf is described below
commit 30d01bf2f315823221308f837632bef208ec331b
Author: wxkwxkwxk1231 <ka...@protonmail.com>
AuthorDate: Fri Mar 26 15:01:40 2021 +0800
[SCB-2224] BeanUtils.getBeanOfType return null when aksk enabled (#2317)
* [fix]cipher beans read before injected
* remove log
* [add]SPI file for Cipher
---
.../servicestage/AKSKAuthHeaderProvider.java | 6 ++++--
.../org.apache.servicecomb.foundation.auth.Cipher | 18 ++++++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/AKSKAuthHeaderProvider.java b/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/AKSKAuthHeaderProvider.java
index 9e0da32..9467ae6 100644
--- a/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/AKSKAuthHeaderProvider.java
+++ b/huawei-cloud/servicestage/src/main/java/org/apache/servicecomb/huaweicloud/servicestage/AKSKAuthHeaderProvider.java
@@ -21,6 +21,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.crypto.Mac;
@@ -35,6 +36,7 @@ import org.apache.servicecomb.foundation.auth.Cipher;
import org.apache.servicecomb.foundation.auth.DefaultCipher;
import org.apache.servicecomb.foundation.auth.ShaAKSKCipher;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -142,8 +144,8 @@ public class AKSKAuthHeaderProvider implements AuthHeaderProvider {
return DefaultCipher.getInstance();
}
- Map<String, Cipher> cipherBeans = BeanUtils.getBeansOfType(Cipher.class);
- return cipherBeans.values().stream().filter(c -> c.name().equals(getCipher())).findFirst()
+ List<Cipher> ciphers = SPIServiceUtils.getOrLoadSortedService(Cipher.class);
+ return ciphers.stream().filter(c -> c.name().equals(getCipher())).findFirst()
.orElseThrow(() -> new IllegalArgumentException("failed to find cipher named " + getCipher()));
}
diff --git a/huawei-cloud/servicestage/src/main/resources/META-INF/services/org.apache.servicecomb.foundation.auth.Cipher b/huawei-cloud/servicestage/src/main/resources/META-INF/services/org.apache.servicecomb.foundation.auth.Cipher
new file mode 100644
index 0000000..e242e7a
--- /dev/null
+++ b/huawei-cloud/servicestage/src/main/resources/META-INF/services/org.apache.servicecomb.foundation.auth.Cipher
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.servicecomb.foundation.auth.ShaAKSKCipher
\ No newline at end of file