From 6d7883adfa6d5dafe885306ca40790e0a11f253d Mon Sep 17 00:00:00 2001
From: Alex <97039406+chengyouling@users.noreply.github.com>
Date: Sat, 26 Oct 2024 09:19:51 +0800
Subject: [PATCH] [#1387] fixed cross engine authentication failed at dual-az
servicecomb engine problem (#1392)
---
pom.xml | 2 +-
.../transport/RBACRequestAuthHeaderProvider.java | 13 ++++++++++---
.../java/com/huaweicloud/config/ConfigService.java | 2 ++
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 97e237256..1abf7cfff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,7 +38,7 @@
import spring-framework-bom. No need configure spring version. -->
2023.0.3
3.3.2
- 2.8.19
+ 2.8.21
diff --git a/spring-cloud-huawei-service-engine/service-engine-common/src/main/java/com/huaweicloud/service/engine/common/transport/RBACRequestAuthHeaderProvider.java b/spring-cloud-huawei-service-engine/service-engine-common/src/main/java/com/huaweicloud/service/engine/common/transport/RBACRequestAuthHeaderProvider.java
index aba11fa95..f4df7e5c6 100644
--- a/spring-cloud-huawei-service-engine/service-engine-common/src/main/java/com/huaweicloud/service/engine/common/transport/RBACRequestAuthHeaderProvider.java
+++ b/spring-cloud-huawei-service-engine/service-engine-common/src/main/java/com/huaweicloud/service/engine/common/transport/RBACRequestAuthHeaderProvider.java
@@ -26,6 +26,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.foundation.auth.AuthHeaderProvider;
+import org.apache.servicecomb.http.client.event.EngineConnectChangedEvent;
import org.apache.servicecomb.service.center.client.OperationEvents;
import org.apache.servicecomb.service.center.client.ServiceCenterClient;
import org.apache.servicecomb.service.center.client.model.RbacTokenRequest;
@@ -81,6 +82,8 @@ public class RBACRequestAuthHeaderProvider implements AuthHeaderProvider {
private int lastStatusCode = 401;
+ private ServiceCenterClient serviceCenterClient;
+
public RBACRequestAuthHeaderProvider(BootstrapProperties bootstrapProperties) {
this.discoveryProperties = bootstrapProperties.getDiscoveryBootstrapProperties();
this.serviceCombSSLProperties = bootstrapProperties.getServiceCombSSLProperties();
@@ -88,6 +91,8 @@ public RBACRequestAuthHeaderProvider(BootstrapProperties bootstrapProperties) {
this.microserviceProperties = bootstrapProperties.getMicroserviceProperties();
if (enabled()) {
+ serviceCenterClient = ServiceCenterUtils.serviceCenterClient(discoveryProperties,
+ serviceCombSSLProperties, Collections.emptyList());
EventManager.getEventBus().register(this);
executorService = Executors.newFixedThreadPool(1, t -> new Thread(t, "rbac-executor"));
@@ -113,6 +118,11 @@ public void onNotPermittedEvent(OperationEvents.UnAuthorizedOperationEvent event
this.executorService.submit(this::retryRefresh);
}
+ @Subscribe
+ public void onEngineConnectChangedEvent(EngineConnectChangedEvent event) {
+ cache.refresh(CACHE_KEY);
+ }
+
protected String createHeaders() {
LOGGER.info("start to create RBAC headers");
@@ -136,9 +146,6 @@ protected String createHeaders() {
}
protected RbacTokenResponse callCreateHeaders() {
- ServiceCenterClient serviceCenterClient = ServiceCenterUtils
- .serviceCenterClient(discoveryProperties, serviceCombSSLProperties,
- Collections.emptyList());
RbacTokenRequest request = new RbacTokenRequest();
request.setName(serviceCombRBACProperties.getName());
request.setPassword(serviceCombRBACProperties.getPassword());
diff --git a/spring-cloud-huawei-service-engine/service-engine-config/src/main/java/com/huaweicloud/config/ConfigService.java b/spring-cloud-huawei-service-engine/service-engine-config/src/main/java/com/huaweicloud/config/ConfigService.java
index 1763b9383..1039daeed 100644
--- a/spring-cloud-huawei-service-engine/service-engine-config/src/main/java/com/huaweicloud/config/ConfigService.java
+++ b/spring-cloud-huawei-service-engine/service-engine-config/src/main/java/com/huaweicloud/config/ConfigService.java
@@ -152,6 +152,7 @@ private void initServiceCenterConfig(BootstrapProperties bootstrapProperties,
bootstrapProperties.getServiceCombSSLProperties(),
authHeaderProviders, HttpTransportFactory.defaultRequestConfig().build());
ConfigCenterClient configCenterClient = new ConfigCenterClient(addressManager, httpTransport);
+ configCenterClient.setEventBus(EventManager.getEventBus());
queryConfigurationsRequest = createQueryConfigurationsRequest(bootstrapProperties);
firstPull(bootstrapProperties.getConfigBootstrapProperties(), configCenterClient, queryConfigurationsRequest,
@@ -254,6 +255,7 @@ private void initKieConfig(BootstrapProperties bootstrapProperties,
authHeaderProviders, requestBuilder.build());
KieConfiguration kieConfiguration = createKieConfiguration(bootstrapProperties);
KieClient kieClient = new KieClient(kieAddressManager, httpTransport, kieConfiguration);
+ kieClient.setEventBus(EventManager.getEventBus());
KieConfigManager kieConfigManager = new KieConfigManager(kieClient, EventManager.getEventBus(), kieConfiguration,
configConverter, kieAddressManager);
kieConfigManager.firstPull();