Skip to content

Commit fb1d737

Browse files
authored
[#1387] fixed cross engine authentication failed at dual-az servicecomb engine problem (#1392) (#1395)
1 parent 90ca438 commit fb1d737

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import spring-framework-bom. No need configure spring version. -->
3939
<spring-cloud.version>2022.0.5</spring-cloud.version>
4040
<spring-boot.version>3.1.12</spring-boot.version>
41-
<servicecomb.version>2.8.19</servicecomb.version>
41+
<servicecomb.version>2.8.21</servicecomb.version>
4242
</properties>
4343

4444
<modules>

spring-cloud-huawei-service-engine/service-engine-common/src/main/java/com/huaweicloud/service/engine/common/transport/RBACRequestAuthHeaderProvider.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.apache.commons.lang3.StringUtils;
2828
import org.apache.servicecomb.foundation.auth.AuthHeaderProvider;
29+
import org.apache.servicecomb.http.client.event.EngineConnectChangedEvent;
2930
import org.apache.servicecomb.service.center.client.OperationEvents;
3031
import org.apache.servicecomb.service.center.client.ServiceCenterClient;
3132
import org.apache.servicecomb.service.center.client.model.RbacTokenRequest;
@@ -81,13 +82,17 @@ public class RBACRequestAuthHeaderProvider implements AuthHeaderProvider {
8182

8283
private int lastStatusCode = 401;
8384

85+
private ServiceCenterClient serviceCenterClient;
86+
8487
public RBACRequestAuthHeaderProvider(BootstrapProperties bootstrapProperties) {
8588
this.discoveryProperties = bootstrapProperties.getDiscoveryBootstrapProperties();
8689
this.serviceCombSSLProperties = bootstrapProperties.getServiceCombSSLProperties();
8790
this.serviceCombRBACProperties = bootstrapProperties.getServiceCombRBACProperties();
8891
this.microserviceProperties = bootstrapProperties.getMicroserviceProperties();
8992

9093
if (enabled()) {
94+
serviceCenterClient = ServiceCenterUtils.serviceCenterClient(discoveryProperties,
95+
serviceCombSSLProperties, Collections.emptyList());
9196
EventManager.getEventBus().register(this);
9297

9398
executorService = Executors.newFixedThreadPool(1, t -> new Thread(t, "rbac-executor"));
@@ -113,6 +118,11 @@ public void onNotPermittedEvent(OperationEvents.UnAuthorizedOperationEvent event
113118
this.executorService.submit(this::retryRefresh);
114119
}
115120

121+
@Subscribe
122+
public void onEngineConnectChangedEvent(EngineConnectChangedEvent event) {
123+
cache.refresh(CACHE_KEY);
124+
}
125+
116126
protected String createHeaders() {
117127
LOGGER.info("start to create RBAC headers");
118128

@@ -136,9 +146,6 @@ protected String createHeaders() {
136146
}
137147

138148
protected RbacTokenResponse callCreateHeaders() {
139-
ServiceCenterClient serviceCenterClient = ServiceCenterUtils
140-
.serviceCenterClient(discoveryProperties, serviceCombSSLProperties,
141-
Collections.emptyList());
142149
RbacTokenRequest request = new RbacTokenRequest();
143150
request.setName(serviceCombRBACProperties.getName());
144151
request.setPassword(serviceCombRBACProperties.getPassword());

spring-cloud-huawei-service-engine/service-engine-common/src/test/java/com/huaweicloud/service/engine/common/transport/RBACRequestAuthHeaderProviderTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@
3434
public class RBACRequestAuthHeaderProviderTest {
3535
private final BootstrapProperties bootstrapProperties = Mockito.mock(BootstrapProperties.class);
3636

37-
private final DiscoveryBootstrapProperties discoveryProperties = Mockito.mock(DiscoveryBootstrapProperties.class);
37+
private final DiscoveryBootstrapProperties discoveryProperties = new DiscoveryBootstrapProperties();
3838

3939
private final ServiceCombSSLProperties serviceCombSSLProperties = Mockito.mock(ServiceCombSSLProperties.class);
4040

4141
private final ServiceCombRBACProperties serviceCombRBACProperties = Mockito.mock(ServiceCombRBACProperties.class);
4242

4343
@BeforeEach
4444
public void setUp() {
45+
discoveryProperties.setAddress("http://127.0.0.1:30100");
4546
Mockito.when(bootstrapProperties.getDiscoveryBootstrapProperties()).thenReturn(discoveryProperties);
4647
Mockito.when(bootstrapProperties.getServiceCombSSLProperties()).thenReturn(serviceCombSSLProperties);
4748
Mockito.when(bootstrapProperties.getServiceCombRBACProperties()).thenReturn(serviceCombRBACProperties);

spring-cloud-huawei-service-engine/service-engine-config/src/main/java/com/huaweicloud/config/ConfigService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ private void initServiceCenterConfig(BootstrapProperties bootstrapProperties,
152152
bootstrapProperties.getServiceCombSSLProperties(),
153153
authHeaderProviders, HttpTransportFactory.defaultRequestConfig().build());
154154
ConfigCenterClient configCenterClient = new ConfigCenterClient(addressManager, httpTransport);
155+
configCenterClient.setEventBus(EventManager.getEventBus());
155156

156157
queryConfigurationsRequest = createQueryConfigurationsRequest(bootstrapProperties);
157158
firstPull(bootstrapProperties.getConfigBootstrapProperties(), configCenterClient, queryConfigurationsRequest,
@@ -254,6 +255,7 @@ private void initKieConfig(BootstrapProperties bootstrapProperties,
254255
authHeaderProviders, requestBuilder.build());
255256
KieConfiguration kieConfiguration = createKieConfiguration(bootstrapProperties);
256257
KieClient kieClient = new KieClient(kieAddressManager, httpTransport, kieConfiguration);
258+
kieClient.setEventBus(EventManager.getEventBus());
257259
KieConfigManager kieConfigManager = new KieConfigManager(kieClient, EventManager.getEventBus(), kieConfiguration,
258260
configConverter, kieAddressManager);
259261
kieConfigManager.firstPull();

0 commit comments

Comments
 (0)