Skip to content

Commit

Permalink
fix: throw insecureHttpWarning message only when attls is not enabled (
Browse files Browse the repository at this point in the history
…#3810)

* throw insecureHttpWarning message only when attls is not enabled

Signed-off-by: sj895092 <shobhackm9@gmail.com>
  • Loading branch information
Shobhajayanna authored Oct 2, 2024
1 parent 6ba9242 commit b846083
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class HttpConfig {

private static final char[] KEYRING_PASSWORD = "password".toCharArray();

@Value("${server.attls.enabled:false}")
private boolean attlsEnabled;
@Value("${server.ssl.protocol:TLSv1.2}")
private String protocol;
@Value("${apiml.httpclient.ssl.enabled-protocols:TLSv1.2,TLSv1.3}")
Expand Down Expand Up @@ -285,7 +287,7 @@ public EurekaJerseyClient eurekaJerseyClient() {

@Bean
public Supplier<EurekaJerseyClientBuilder> eurekaJerseyClientBuilder() {
return () -> factory.createEurekaJerseyClientBuilder(eurekaServerUrl, serviceId);
return () -> factory.createEurekaJerseyClientBuilder(eurekaServerUrl, serviceId, attlsEnabled);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public class ConnectionsConfig {
@Value("${spring.application.name}")
private String serviceId;

@Value("${server.attls.enabled:false}")
private boolean attlsEnabled;

@Value("${server.ssl.trustStoreRequired:false}")
private boolean trustStoreRequired;

Expand Down Expand Up @@ -234,7 +237,7 @@ SslContext sslContext(boolean setKeystore) {

@Bean("primaryApimlEurekaJerseyClient")
EurekaJerseyClient getEurekaJerseyClient() {
return factory().createEurekaJerseyClientBuilder(eurekaServerUrl, serviceId).build();
return factory().createEurekaJerseyClientBuilder(eurekaServerUrl, serviceId, attlsEnabled).build();
}

@Bean(destroyMethod = "shutdown")
Expand Down Expand Up @@ -292,7 +295,7 @@ private CloudEurekaClient registerInTheApimlInstance(EurekaClientConfig config,
BeanUtils.copyProperties(config, configBean);
configBean.setServiceUrl(urls);

EurekaJerseyClient jerseyClient = factory().createEurekaJerseyClientBuilder(eurekaServerUrl, serviceId).build();
EurekaJerseyClient jerseyClient = factory().createEurekaJerseyClientBuilder(eurekaServerUrl, serviceId, attlsEnabled).build();
MutableDiscoveryClientOptionalArgs args = new MutableDiscoveryClientOptionalArgs();
args.setEurekaJerseyClient(jerseyClient);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -83,7 +84,7 @@ class WhenInitializingAdditionalRegistrations {
public void setUp() {
configSpy = Mockito.spy(connectionsConfig);
lenient().doReturn(httpsFactory).when(configSpy).factory();
lenient().when(httpsFactory.createEurekaJerseyClientBuilder(any(), any())).thenReturn(mock(EurekaJerseyClientImpl.EurekaJerseyClientBuilder.class));
lenient().when(httpsFactory.createEurekaJerseyClientBuilder(any(), any(), anyBoolean())).thenReturn(mock(EurekaJerseyClientImpl.EurekaJerseyClientBuilder.class));

lenient().when(eurekaFactory.createCloudEurekaClient(any(), any(), clientConfigCaptor.capture(), any(), any())).thenReturn(additionalClientOne, additionalClientTwo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public HostnameVerifier getHostnameVerifier() {
}
}

public EurekaJerseyClientBuilder createEurekaJerseyClientBuilder(String eurekaServerUrl, String serviceId) {
public EurekaJerseyClientBuilder createEurekaJerseyClientBuilder(String eurekaServerUrl, String serviceId, boolean attlsEnabled) {
EurekaJerseyClientBuilder builder = new EurekaJerseyClientBuilder();
builder.withClientName(serviceId);
builder.withMaxTotalConnections(10);
Expand All @@ -248,10 +248,11 @@ public EurekaJerseyClientBuilder createEurekaJerseyClientBuilder(String eurekaSe
// See:
// https://github.com/Netflix/eureka/blob/master/eureka-core/src/main/java/com/netflix/eureka/transport/JerseyReplicationClient.java#L160
if (eurekaServerUrl.startsWith("http://")) {
apimlLog.log("org.zowe.apiml.common.insecureHttpWarning");
if (!attlsEnabled) {
apimlLog.log("org.zowe.apiml.common.insecureHttpWarning");
}
} else {
builder.withCustomSSL(getSslContext());

builder.withHostnameVerifier(getHostnameVerifier());
}
return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class HttpsFactoryTest {
private static final String EUREKA_URL_NO_SCHEME = "://localhost:10011/eureka/";
private static final String TEST_SERVICE_ID = "service1";
private static final boolean ATTLS = false;
private static final String INCORRECT_PARAMETER_VALUE = "WRONG";

private HttpsConfig.HttpsConfigBuilder httpsConfigBuilder;
Expand Down Expand Up @@ -136,7 +137,7 @@ void shouldCreateEurekaJerseyClientBuilderForHttps() {
HttpsConfig httpsConfig = httpsConfigBuilder.build();
HttpsFactory httpsFactory = new HttpsFactory(httpsConfig);
EurekaJerseyClientImpl.EurekaJerseyClientBuilder clientBuilder =
httpsFactory.createEurekaJerseyClientBuilder("https" + EUREKA_URL_NO_SCHEME, TEST_SERVICE_ID);
httpsFactory.createEurekaJerseyClientBuilder("https" + EUREKA_URL_NO_SCHEME, TEST_SERVICE_ID, ATTLS);
assertNotNull(clientBuilder);
}

Expand All @@ -145,7 +146,7 @@ void shouldCreateEurekaJerseyClientBuilderForHttp() {
HttpsConfig httpsConfig = httpsConfigBuilder.build();
HttpsFactory httpsFactory = new HttpsFactory(httpsConfig);
EurekaJerseyClientImpl.EurekaJerseyClientBuilder clientBuilder =
httpsFactory.createEurekaJerseyClientBuilder("http" + EUREKA_URL_NO_SCHEME, TEST_SERVICE_ID);
httpsFactory.createEurekaJerseyClientBuilder("http" + EUREKA_URL_NO_SCHEME, TEST_SERVICE_ID, ATTLS);
assertNotNull(clientBuilder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public class ApiMediationServiceConfig {
* XML Path: /instance/app
*/
private String serviceId;
/**
* to verify if Attls is enabled for the service
*/
private boolean attlsEnabled;

/**
* * **title** (XML Path: /instance/metadata/apiml.service.title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private EurekaClient initializeEurekaClient(
HttpsFactory factory = new HttpsFactory(httpsConfig);

EurekaJerseyClient eurekaJerseyClient = factory.createEurekaJerseyClientBuilder(
config.getDiscoveryServiceUrls().get(0), config.getServiceId()).build();
config.getDiscoveryServiceUrls().get(0), config.getServiceId(), config.isAttlsEnabled()).build();

AbstractDiscoveryClientOptionalArgs<?> args = new DiscoveryClient.DiscoveryClientOptionalArgs();
args.setEurekaJerseyClient(eurekaJerseyClient);
Expand Down

0 comments on commit b846083

Please sign in to comment.