Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1387] fixed cross engine authentication failed at dual-az servicecomb engine problem (#1392) #1394

Merged
merged 2 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import spring-framework-bom. No need configure spring version. -->
<spring-cloud.version>2023.0.3</spring-cloud.version>
<spring-boot.version>3.3.2</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 @@ -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;
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 @@ -34,14 +34,15 @@
public class RBACRequestAuthHeaderProviderTest {
private final BootstrapProperties bootstrapProperties = Mockito.mock(BootstrapProperties.class);

private final DiscoveryBootstrapProperties discoveryProperties = Mockito.mock(DiscoveryBootstrapProperties.class);
private final DiscoveryBootstrapProperties discoveryProperties = new DiscoveryBootstrapProperties();

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

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

@BeforeEach
public void setUp() {
discoveryProperties.setAddress("http://127.0.0.1:30100");
Mockito.when(bootstrapProperties.getDiscoveryBootstrapProperties()).thenReturn(discoveryProperties);
Mockito.when(bootstrapProperties.getServiceCombSSLProperties()).thenReturn(serviceCombSSLProperties);
Mockito.when(bootstrapProperties.getServiceCombRBACProperties()).thenReturn(serviceCombRBACProperties);
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
Loading