Skip to content

Commit

Permalink
[#1387] fixed cross engine authentication failed at dual-az serviceco…
Browse files Browse the repository at this point in the history
…mb engine problem (#1392)
  • Loading branch information
chengyouling authored Oct 26, 2024
1 parent 33b0e7f commit f28f99a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import spring-framework-bom. No need configure spring version. -->
<spring-cloud.version>2021.0.9</spring-cloud.version>
<spring-boot.version>2.7.18</spring-boot.version>
<servicecomb.version>2.8.19</servicecomb.version>
<servicecomb.version>2.8.21</servicecomb.version>
</properties>

<modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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;
Expand Down Expand Up @@ -81,13 +82,17 @@ public class RBACRequestAuthHeaderProvider implements AuthHeaderProvider {

private int lastStatusCode = 401;

private ServiceCenterClient serviceCenterClient;

public RBACRequestAuthHeaderProvider(BootstrapProperties bootstrapProperties) {
this.discoveryProperties = bootstrapProperties.getDiscoveryBootstrapProperties();
this.serviceCombSSLProperties = bootstrapProperties.getServiceCombSSLProperties();
this.serviceCombRBACProperties = bootstrapProperties.getServiceCombRBACProperties();
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"));
Expand All @@ -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");

Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f28f99a

Please sign in to comment.