From 3f9dbd53d0370d21a29321de8aaf7e84bce7465f Mon Sep 17 00:00:00 2001 From: Kalpa Vidusha Pathirana Date: Tue, 16 Dec 2025 00:17:33 +0530 Subject: [PATCH 1/2] Integrate HashiCorp Vault & Secure Database Configs - Downgraded Spring Boot to 3.2.5 to support Spring Cloud Vault compatibility. - Added 'spring-cloud-starter-vault-config' dependency. - Migrated 'application.properties' to 'application.yml'. - Externalized database credentials to HashiCorp Vault to implement Zero Trust security. --- pom.xml | 162 ++++++++++-------- src/main/resources/application.properties | 5 - src/main/resources/application.yml | 29 ++++ .../controller/BuilderControllerTest.java | 2 +- .../controller/CategoryControllerTest.java | 2 +- .../controller/ProductControllerTest.java | 9 +- .../controller/ReviewControllerTest.java | 2 +- 7 files changed, 126 insertions(+), 85 deletions(-) delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yml diff --git a/pom.xml b/pom.xml index 65919de..e85c7f8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,80 +1,96 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 4.0.0 - - - com.CSO2 - product-catalogue-service - 0.0.1-SNAPSHOT - product-catalogue-service - product-catalogue-service of CSO2 - - 17 - 1.18.42 - - - - org.springframework.boot - spring-boot-starter-data-mongodb - - - org.springframework.boot - spring-boot-starter-web - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.5 + + com.CSO2 + product-catalogue-service + 0.0.1-SNAPSHOT + product-catalogue-service + product-catalogue-service of CSO2 + + 17 + 1.18.42 + 2023.0.0 - - org.projectlombok - lombok - ${lombok.version} - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-devtools - runtime - true - - + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.projectlombok - lombok - ${lombok.version} - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - + + + org.springframework.cloud + spring-cloud-starter-vault-config + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + ${lombok.version} + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + ${lombok.version} + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index f444e17..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,5 +0,0 @@ -spring.application.name=product-catalogue-service -server.port=${SERVER_PORT:8082} - -# MongoDB Configuration (override via env vars in production) -spring.data.mongodb.uri=${MONGODB_URI:mongodb://localhost:27017/CSO2_product_catalogue_service} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..ffb7626 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,29 @@ +# --- Product Catalogue Service --- +spring: + application: + name: product-catalogue-service + + # 1. Load Vault + config: + import: "optional:vault://" + + # 2. Vault Config + cloud: + vault: + enabled: true + uri: http://localhost:8200 + token: my-root-token + kv: + enabled: true + backend: kv + default-context: cs02-app + authentication: TOKEN + + # 3. MongoDB Config (Using a unique key for this service) + data: + mongodb: + uri: ${product_mongodb_uri:mongodb://localhost:27017/CSO2_product_catalogue_service} + +# --- Server Port --- +server: + port: 8082 \ No newline at end of file diff --git a/src/test/java/com/CSO2/product_catalogue_service/controller/BuilderControllerTest.java b/src/test/java/com/CSO2/product_catalogue_service/controller/BuilderControllerTest.java index d6881d8..8808e09 100644 --- a/src/test/java/com/CSO2/product_catalogue_service/controller/BuilderControllerTest.java +++ b/src/test/java/com/CSO2/product_catalogue_service/controller/BuilderControllerTest.java @@ -3,7 +3,7 @@ import com.CSO2.product_catalogue_service.dto.request.CompatibilityCheckRequest; import com.CSO2.product_catalogue_service.dto.response.BuilderSuggestionDTO; import com.CSO2.product_catalogue_service.service.BuilderService; -import tools.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/src/test/java/com/CSO2/product_catalogue_service/controller/CategoryControllerTest.java b/src/test/java/com/CSO2/product_catalogue_service/controller/CategoryControllerTest.java index 17afcca..2bb35d7 100644 --- a/src/test/java/com/CSO2/product_catalogue_service/controller/CategoryControllerTest.java +++ b/src/test/java/com/CSO2/product_catalogue_service/controller/CategoryControllerTest.java @@ -2,7 +2,7 @@ import com.CSO2.product_catalogue_service.model.Category; import com.CSO2.product_catalogue_service.service.CategoryService; -import tools.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/src/test/java/com/CSO2/product_catalogue_service/controller/ProductControllerTest.java b/src/test/java/com/CSO2/product_catalogue_service/controller/ProductControllerTest.java index 702a140..ede1b94 100644 --- a/src/test/java/com/CSO2/product_catalogue_service/controller/ProductControllerTest.java +++ b/src/test/java/com/CSO2/product_catalogue_service/controller/ProductControllerTest.java @@ -5,7 +5,8 @@ import com.CSO2.product_catalogue_service.dto.response.ProductListDTO; import com.CSO2.product_catalogue_service.model.Product; import com.CSO2.product_catalogue_service.service.ProductService; -import tools.jackson.databind.ObjectMapper; +// ✅ FIXED: Using the standard Jackson library +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -130,8 +131,8 @@ void createProduct_ShouldReturnCreatedProduct() throws Exception { when(productService.createProduct(any(ProductCreateRequest.class))).thenReturn(product); mockMvc.perform(post("/api/products") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request))) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) .andExpect(status().isOk()) .andExpect(jsonPath("$.id").value("1")) .andExpect(jsonPath("$.name").value("New Product")); @@ -162,4 +163,4 @@ protected void writeInternal(Object o, HttpOutputMessage outputMessage) objectMapper.writeValue(outputMessage.getBody(), o); } } -} +} \ No newline at end of file diff --git a/src/test/java/com/CSO2/product_catalogue_service/controller/ReviewControllerTest.java b/src/test/java/com/CSO2/product_catalogue_service/controller/ReviewControllerTest.java index e5fd389..e1d74a3 100644 --- a/src/test/java/com/CSO2/product_catalogue_service/controller/ReviewControllerTest.java +++ b/src/test/java/com/CSO2/product_catalogue_service/controller/ReviewControllerTest.java @@ -4,7 +4,7 @@ import com.CSO2.product_catalogue_service.model.Review; import com.CSO2.product_catalogue_service.repository.ReviewRepository; import com.CSO2.product_catalogue_service.service.ReviewService; -import tools.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; From 0469bcb31d4d0d9ff6535a1eaa091e0005c82946 Mon Sep 17 00:00:00 2001 From: Kalpa Vidusha Pathirana Date: Sun, 22 Mar 2026 20:00:48 +0530 Subject: [PATCH 2/2] Update application.properties --- src/main/resources/application.properties | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/resources/application.properties diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..4101c4c --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,7 @@ +spring.application.name=product-catalogue-service +server.port=${SERVER_PORT:8082} + +# MongoDB Configuration +# URI is injected at runtime from HashiCorp Vault (secret/cso2/services/product-catalogue-service-mongo) +# In K8s: DATABASE_PASSWORD env var is populated from Vault, then MONGODB_URI is constructed +spring.data.mongodb.uri=${MONGODB_URI:mongodb://localhost:27017/CSO2_product_catalogue_service}