Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.solace.maas.ep.event.management.agent.webProxy;
package com.solace.maas.ep.event.management.agent.plugin.config;

import com.solace.maas.ep.event.management.agent.plugin.config.VMRProperties;
import com.solace.maas.ep.event.management.agent.plugin.config.eventPortal.EventPortalPluginProperties;
import com.solace.maas.ep.event.management.agent.plugin.config.eventPortal.GatewayProperties;
import com.solace.maas.ep.event.management.agent.plugin.config.eventPortal.GatewayMessagingProperties;
import com.solace.maas.ep.event.management.agent.plugin.config.eventPortal.GatewayProperties;
import com.solace.maas.ep.event.management.agent.plugin.messagingService.MessagingServiceConnectionProperties;
import com.solace.maas.ep.event.management.agent.plugin.messagingService.MessagingServiceUsersProperties;
import lombok.SneakyThrows;
Expand All @@ -22,6 +21,11 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ActiveProfiles("TEST")
Expand Down Expand Up @@ -256,4 +260,38 @@ void testNoGatewayConnectionProperties() {
.hasCauseExactlyInstanceOf(NoSuchElementException.class)
.hasRootCauseMessage("Event Portal gateway connection properties not found.");
}

@Test
@SneakyThrows
void testSetDefaultTrustStoreCalledWhenCustomCaCertsPresent() {
// Spy on vmrProperties to mock getCustomCaCertsPresentEnv and verify setDefaultTrustStore is called
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment references a non-existent method getCustomCaCertsPresentEnv. It should reference isCustomCACertConfigured instead to match the actual method being mocked.

Copilot uses AI. Check for mistakes.
VMRProperties spyVmrProperties = spy(vmrProperties);
when(spyVmrProperties.isCustomCACertConfigured()).thenReturn(true);
doNothing().when(spyVmrProperties).setDefaultTrustStore(any(Properties.class));

MessagingServiceConnectionProperties connectionProps = createConnectionProperties(false, null, null, null, null, null);
when(gatewayMessagingProperties.getConnections()).thenReturn(Collections.singletonList(connectionProps));

spyVmrProperties.getVmrProperties();

// Verify setDefaultTrustStore was called
verify(spyVmrProperties).setDefaultTrustStore(any(Properties.class));
}

@Test
@SneakyThrows
void testSetDefaultTrustStoreNotCalledWhenCustomCaCertsNotPresent() {
// Spy on vmrProperties to mock getCustomCaCertsPresentEnv and verify setDefaultTrustStore is NOT called
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment references a non-existent method getCustomCaCertsPresentEnv. It should reference isCustomCACertConfigured instead to match the actual method being mocked.

Suggested change
// Spy on vmrProperties to mock getCustomCaCertsPresentEnv and verify setDefaultTrustStore is NOT called
// Spy on vmrProperties to mock isCustomCACertConfigured and verify setDefaultTrustStore is NOT called

Copilot uses AI. Check for mistakes.
VMRProperties spyVmrProperties = spy(vmrProperties);
when(spyVmrProperties.isCustomCACertConfigured()).thenReturn(false);

MessagingServiceConnectionProperties connectionProps = createConnectionProperties(false, null, null, null, null, null);
when(gatewayMessagingProperties.getConnections()).thenReturn(Collections.singletonList(connectionProps));

spyVmrProperties.getVmrProperties();

// Verify setDefaultTrustStore was NOT called
verify(spyVmrProperties, never()).setDefaultTrustStore(any(Properties.class));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -122,9 +125,51 @@ public Properties getVmrProperties() {
properties.setProperty(SolaceProperties.AuthenticationProperties.SCHEME_BASIC_PASSWORD, password);
properties.setProperty(SolaceProperties.ClientProperties.NAME, clientName);

//We will always use the default jks truststore for connecting to the EVMR
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states 'We will always use the default jks truststore' but the implementation only configures it when CUSTOM_CA_CERTS_PRESENT=1. Update the comment to accurately reflect the conditional behavior.

Suggested change
//We will always use the default jks truststore for connecting to the EVMR
// Explicitly configure the default JKS truststore for connecting to the EVMR only when custom CA certificates are present

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this comment 👍

configureDefaultTrustStore(properties);

return properties;
}

private void configureDefaultTrustStore(Properties properties) {
if (properties == null) {
log.warn("Properties object is null");
return;
}

if (!isCustomCACertConfigured()) {
log.debug("Custom CA certificates not present. Skipping explicit default truststore configuration.");
return;
}

setDefaultTrustStore(properties);
}


boolean isCustomCACertConfigured() {
String customCaCertsPresent = System.getenv("CUSTOM_CA_CERTS_PRESENT");

return ("1".equals(customCaCertsPresent));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package private to aid in testing

Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name isCustomCACertConfigured is misleading - it checks whether custom CA certs are present, not whether they are configured. Consider renaming to hasCustomCACerts or isCustomCACertPresent to better reflect what it checks.

Copilot uses AI. Check for mistakes.

void setDefaultTrustStore(Properties properties) {
String javaHome = System.getProperty("java.home");
if (StringUtils.isBlank(javaHome)) {
log.warn("java.home system property is not set. Cannot configure default truststore for JCSMP.");
return;
}
Path defaultTrustStorePath = Paths.get(javaHome, "lib", "security", "cacerts");
File trustStoreFile = defaultTrustStorePath.toFile();

if (!trustStoreFile.exists() || !trustStoreFile.canRead()) {
log.warn("Default truststore not found or not readable at: {}. JCSMP connection may fail.", defaultTrustStorePath);
return;
}

log.debug("Custom CA certificates present. Explicitly configuring EVMR connection to use default truststore: {}", defaultTrustStorePath);
properties.setProperty(SolaceProperties.TransportLayerSecurityProperties.TRUST_STORE_PATH, defaultTrustStorePath.toString());
}

Comment on lines 151 to 168
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package private to help in testing

public List<String> getRTOSessionProperties() {
parseVmrProperties();

Expand Down