Add ability to turn off SSL 49/140649/1
authorsaul.gill <saul.gill@est.tech>
Tue, 1 Apr 2025 13:31:29 +0000 (14:31 +0100)
committersaul.gill <saul.gill@est.tech>
Tue, 1 Apr 2025 15:46:51 +0000 (16:46 +0100)
Issue-ID: CCSDK-4110
Change-Id: If5e962a426e55250da6daf48a06cd4b68b1d7891
Signed-off-by: saul.gill <saul.gill@est.tech>
a1-policy-management/config/application.yaml
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/BeanFactory.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientFactory.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfig.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientConfig.java
a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java
a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java
a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterDisableTest.java
a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/ReactiveEntryExitFilterTest.java
a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java

index 95c5f75..4b1dbce 100644 (file)
@@ -121,6 +121,7 @@ server:
   http-port: 8081
   shutdown: "graceful"
   ssl:
+    enabled: true
     key-store-type: JKS
     key-store-password: policy_agent
     key-store: /opt/app/policy-agent/etc/cert/keystore.jks
index 4d1fa33..4d825f8 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP : ccsdk oran
  * ======================================================================
  * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
- * Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved.
+ * Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
  * ======================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ import org.springframework.context.annotation.Configuration;
 @Configuration
 public class BeanFactory {
 
-    @Value("${server.http-port}")
+    @Value("${server.http-port:0}")
     private int httpPort = 0;
 
     @Bean
index 204af9c..6d642a3 100644 (file)
@@ -3,6 +3,8 @@
  * ONAP : ccsdk oran
  * ======================================================================
  * Copyright (C) 2019-2022 Nordix Foundation. All rights reserved.
+ * Modifications Copyright (C) 2025 OpenInfra Foundation Europe.
+ * All rights reserved.
  * ======================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -59,7 +61,12 @@ public class AsyncRestClientFactory {
 
     public AsyncRestClientFactory(WebClientConfig clientConfig, SecurityContext securityContext) {
         if (clientConfig != null) {
-            this.sslContextFactory = new CachingSslContextFactory(clientConfig);
+            if (clientConfig.isSslEnabled()) {
+                this.sslContextFactory = new CachingSslContextFactory(clientConfig);
+            } else {
+                this.sslContextFactory = null;
+                logger.debug("SSL is turned OFF for the web client");
+            }
             this.httpProxyConfig = clientConfig.getHttpProxyConfig();
         } else {
             logger.warn("No configuration for web client defined, HTTPS will not work");
index 6d8d52d..360369c 100644 (file)
@@ -3,7 +3,8 @@
  * ONAP : ccsdk oran
  * ======================================================================
  * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
- * Modifications Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
+ * Modifications Copyright (C) 2023-2025 OpenInfra Foundation Europe.
+ * All rights reserved.
  * ======================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -39,36 +40,40 @@ import reactor.netty.transport.ProxyProvider;
 public class ApplicationConfig {
 
     @Getter
-    @Value("${app.filepath}")
+    @Value("${app.filepath:null}")
     private String localConfigurationFilePath;
 
     @Getter
-    @Value("${app.config-file-schema-path:}")
+    @Value("${app.config-file-schema-path:null}")
     private String configurationFileSchemaPath;
 
     @Getter
     @Value("${app.vardata-directory:null}")
     private String vardataDirectory;
 
-    @Value("${server.ssl.key-store-type}")
+    @Getter
+    @Value("${server.ssl.enabled:true}")
+    private boolean sslEnabled;
+
+    @Value("${server.ssl.key-store-type:null}")
     private String sslKeyStoreType = "";
 
-    @Value("${server.ssl.key-store-password}")
+    @Value("${server.ssl.key-store-password:null}")
     private String sslKeyStorePassword = "";
 
-    @Value("${server.ssl.key-store}")
+    @Value("${server.ssl.key-store:null}")
     private String sslKeyStore = "";
 
-    @Value("${server.ssl.key-password}")
+    @Value("${server.ssl.key-password:null}")
     private String sslKeyPassword = "";
 
-    @Value("${app.webclient.trust-store-used}")
+    @Value("${app.webclient.trust-store-used:false}")
     private boolean sslTrustStoreUsed = false;
 
-    @Value("${app.webclient.trust-store-password}")
+    @Value("${app.webclient.trust-store-password:null}")
     private String sslTrustStorePassword = "";
 
-    @Value("${app.webclient.trust-store}")
+    @Value("${app.webclient.trust-store:null}")
     private String sslTrustStore = "";
 
     @Value("${app.webclient.http.proxy-host:}")
@@ -133,17 +138,26 @@ public class ApplicationConfig {
                     .httpProxyPort(this.httpProxyPort) //
                     .httpProxyType(ProxyProvider.Proxy.valueOf(this.httpProxyType)) //
                     .build();
+            if (sslEnabled) {
+                this.webClientConfig = WebClientConfig.builder() //
+                        .sslEnabled(true)
+                        .keyStoreType(this.sslKeyStoreType) //
+                        .keyStorePassword(this.sslKeyStorePassword) //
+                        .keyStore(this.sslKeyStore) //
+                        .keyPassword(this.sslKeyPassword) //
+                        .isTrustStoreUsed(this.sslTrustStoreUsed) //
+                        .trustStore(this.sslTrustStore) //
+                        .trustStorePassword(this.sslTrustStorePassword) //
+                        .httpProxyConfig(httpProxyConfig) //
+                        .build();
+            } else {
+                this.webClientConfig = WebClientConfig.builder() //
+                        .sslEnabled(false)
+                        .isTrustStoreUsed(false)
+                        .httpProxyConfig(httpProxyConfig) //
+                        .build();
+            }
 
-            this.webClientConfig = WebClientConfig.builder() //
-                    .keyStoreType(this.sslKeyStoreType) //
-                    .keyStorePassword(this.sslKeyStorePassword) //
-                    .keyStore(this.sslKeyStore) //
-                    .keyPassword(this.sslKeyPassword) //
-                    .isTrustStoreUsed(this.sslTrustStoreUsed) //
-                    .trustStore(this.sslTrustStore) //
-                    .trustStorePassword(this.sslTrustStorePassword) //
-                    .httpProxyConfig(httpProxyConfig) //
-                    .build();
         }
         return this.webClientConfig;
     }
index ab2958c..1f22d99 100644 (file)
@@ -3,6 +3,8 @@
  * ONAP : ccsdk oran
  * ======================================================================
  * Copyright (C) 2020-2023 Nordix Foundation. All rights reserved.
+ * Modifications Copyright (C) 2025 OpenInfra Foundation Europe.
+ * All rights reserved.
  * ======================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,13 +25,15 @@ package org.onap.ccsdk.oran.a1policymanagementservice.configuration;
 import lombok.Builder;
 import lombok.Getter;
 import lombok.ToString;
-
 import reactor.netty.transport.ProxyProvider;
 
 @Builder
 @Getter
 @ToString
 public class WebClientConfig {
+
+    private boolean sslEnabled;
+
     private String keyStoreType;
 
     private String keyStorePassword;
index 5ed8642..864a1c5 100644 (file)
@@ -3,6 +3,8 @@
  * ONAP : ccsdk oran
  * ======================================================================
  * Copyright (C) 2019-2023 Nordix Foundation. All rights reserved.
+ * Modifications Copyright (C) 2025 OpenInfra Foundation Europe.
+ * All rights reserved.
  * ======================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -1170,6 +1172,7 @@ class ApplicationTest {
     private AsyncRestClient restClient(String baseUrl, boolean useTrustValidation) {
         WebClientConfig config = this.applicationConfig.getWebClientConfig();
         config = WebClientConfig.builder()
+                .sslEnabled(config.isSslEnabled())
                 .keyStoreType(config.getKeyStoreType())
                 .keyStorePassword(config.getKeyStorePassword())
                 .keyStore(config.getKeyStore())
@@ -1185,8 +1188,12 @@ class ApplicationTest {
 
     }
 
-    private String baseUrl() {
-        return "https://localhost:" + port;
+    public String baseUrl() {
+        if (applicationConfig.isSslEnabled()) {
+            return "https://localhost:" + port;
+        } else {
+            return "http://localhost:" + port;
+        }
     }
 
     private AsyncRestClient restClient(boolean useTrustValidation) {
index e46b836..05f82c6 100644 (file)
@@ -1,6 +1,8 @@
 /*-
  * ========================LICENSE_START=================================
  * Copyright (C) 2020-2023 Nordix Foundation. All rights reserved.
+ * Modifications Copyright (C) 2025 OpenInfra Foundation Europe.
+ * All rights reserved.
  * ======================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -64,8 +66,6 @@ import reactor.test.StepVerifier;
         "app.config-file-schema-path=/application_configuration_schema.json" //
 })
 class ConfigurationControllerTest {
-    @Autowired
-    ApplicationContext context;
 
     @Autowired
     ApplicationConfig applicationConfig;
@@ -166,19 +166,28 @@ class ConfigurationControllerTest {
 
     private AsyncRestClient restClient() {
         WebClientConfig config = this.applicationConfig.getWebClientConfig();
-        config = WebClientConfig.builder() //
-                .keyStoreType(config.getKeyStoreType()) //
-                .keyStorePassword(config.getKeyStorePassword()) //
-                .keyStore(config.getKeyStore()) //
-                .keyPassword(config.getKeyPassword()) //
-                .isTrustStoreUsed(false) //
-                .trustStore(config.getTrustStore()) //
-                .trustStorePassword(config.getTrustStorePassword()) //
-                .httpProxyConfig(config.getHttpProxyConfig()) //
-                .build();
-
-        AsyncRestClientFactory f = new AsyncRestClientFactory(config, new SecurityContext(""));
-        return f.createRestClientNoHttpProxy("https://localhost:" + port);
 
+        if (applicationConfig.isSslEnabled()) {
+            config = WebClientConfig.builder() //
+                    .sslEnabled(applicationConfig.isSslEnabled())
+                    .keyStoreType(config.getKeyStoreType()) //
+                    .keyStorePassword(config.getKeyStorePassword()) //
+                    .keyStore(config.getKeyStore()) //
+                    .keyPassword(config.getKeyPassword()) //
+                    .isTrustStoreUsed(config.isTrustStoreUsed()) //
+                    .trustStore(config.getTrustStore()) //
+                    .trustStorePassword(config.getTrustStorePassword()) //
+                    .httpProxyConfig(config.getHttpProxyConfig()) //
+                    .build();
+
+            AsyncRestClientFactory f = new AsyncRestClientFactory(config, new SecurityContext(""));
+            return f.createRestClientNoHttpProxy("https://localhost:" + port);
+        } else {
+            config = WebClientConfig.builder()
+                    .httpProxyConfig(config.getHttpProxyConfig())
+                    .build();
+            AsyncRestClientFactory f = new AsyncRestClientFactory(config, new SecurityContext(""));
+            return f.createRestClientNoHttpProxy("http://localhost:" + port);
+        }
     }
 }
index 2904a06..36e8823 100644 (file)
@@ -163,7 +163,7 @@ class PolicyControllerV3Test {
         Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
         testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
                 responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
-        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/"));
     }
 
 
@@ -179,7 +179,7 @@ class PolicyControllerV3Test {
         Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
         testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
                 responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
-        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/"));
     }
 
 
@@ -195,7 +195,7 @@ class PolicyControllerV3Test {
         Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
         testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
                 responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
-        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/"));
     }
 
 
@@ -211,7 +211,7 @@ class PolicyControllerV3Test {
         Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
         testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
                 responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
-        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/"));
     }
 
     @Test
@@ -237,7 +237,7 @@ class PolicyControllerV3Test {
         testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
         String policyBody = testHelperTest.postBadPolicyBody(nonRtRicId, policyTypeName, "");
         Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
-        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/"));
     }
 
     @Test
@@ -250,7 +250,7 @@ class PolicyControllerV3Test {
         testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
         String policyBody = testHelperTest.postBadPolicyBody(nonRtRicId, policyTypeName, "");
         Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
-        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/"));
     }
 
     @Test
@@ -262,7 +262,7 @@ class PolicyControllerV3Test {
         testHelperTest.addPolicyType(policyTypeName, nonRtRicId);
         String policyBody = testHelperTest.postPolicyBody(nonRtRicId, policyTypeName, "1");
         Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
-        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/1"));
+        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/1"));
     }
 
     @Test
index 54b9d29..94ab47d 100644 (file)
@@ -1,3 +1,23 @@
+/*-
+ * ========================LICENSE_START=================================
+ * ONAP : ccsdk oran
+ * ======================================================================
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
+ * ======================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================LICENSE_END===================================
+ */
+
 package org.onap.ccsdk.oran.a1policymanagementservice.utils.v3;
 
 import org.junit.jupiter.api.AfterAll;
@@ -24,7 +44,6 @@ import java.lang.invoke.MethodHandles;
 import java.nio.file.Path;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
 
 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 @ExtendWith({OutputCaptureExtension.class})
@@ -74,7 +93,7 @@ class ReactiveEntryExitFilterDisableTest {
         Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
         testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
                 responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
-        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/"));
         assertFalse(capturedOutput.getOut().contains("Request received with path: /a1-policy-management/v1/policies"));
         assertFalse(capturedOutput.getOut().contains("the Status code of the response: 201 CREATED"));
         assertFalse(capturedOutput.getOut().contains("the response is:"));
index 9e0f60e..0086c1e 100644 (file)
@@ -1,3 +1,23 @@
+/*-
+ * ========================LICENSE_START=================================
+ * ONAP : ccsdk oran
+ * ======================================================================
+ * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
+ * ======================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================LICENSE_END===================================
+ */
+
 package org.onap.ccsdk.oran.a1policymanagementservice.utils.v3;
 
 import org.junit.jupiter.api.AfterAll;
@@ -74,7 +94,7 @@ class ReactiveEntryExitFilterTest {
         Mono<ResponseEntity<String>> responseMono = testHelperTest.restClientV3().postForEntity(url, policyBody);
         testHelperTest.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
                 responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
-        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1-policy-management/v1/policies/"));
+        testHelperTest.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains(testHelperTest.baseUrl() + "/a1-policy-management/v1/policies/"));
         assertTrue(capturedOutput.getOut().contains("Request received with path: /a1-policy-management/v1/policies"));
         assertTrue(capturedOutput.getOut().contains("the Status code of the response: 201 CREATED"));
         assertTrue(capturedOutput.getOut().contains("the response is:"));
index a7b8cc9..a9ff597 100644 (file)
@@ -93,6 +93,7 @@ public class TestHelperTest {
     public AsyncRestClient restClient(String baseUrl, boolean useTrustValidation) {
         WebClientConfig config = this.applicationConfig.getWebClientConfig();
         config = WebClientConfig.builder()
+                .sslEnabled(config.isSslEnabled())
                 .keyStoreType(config.getKeyStoreType())
                 .keyStorePassword(config.getKeyStorePassword())
                 .keyStore(config.getKeyStore())
@@ -109,7 +110,11 @@ public class TestHelperTest {
     }
 
     public String baseUrl() {
-        return "https://localhost:" + port;
+        if (applicationConfig.isSslEnabled()) {
+            return "https://localhost:" + port;
+        } else {
+            return "http://localhost:" + port;
+        }
     }
 
     public AsyncRestClient restClientV3(boolean useTrustValidation) {