From e2fe2363b69394ceaf8a40c30120dacbc615712b Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 30 Sep 2026 16:16:10 +0000 Subject: [PATCH 1/2] COG-1158: read datasource credentials from DB_USER/DB_PASSWORD env vars Co-Authored-By: patrick.bradley --- README.md | 18 ++++++++++ UserFront/.gitignore | 5 ++- .../application-local.properties.example | 7 ++++ .../config/DataSourcePasswordCheck.java | 33 +++++++++++++++++++ .../src/main/resources/application.properties | 6 ++-- 5 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 UserFront/application-local.properties.example create mode 100644 UserFront/src/main/java/com/userFront/config/DataSourcePasswordCheck.java diff --git a/README.md b/README.md index 1cab94b9..c0854688 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,21 @@ It is mainly used by Admin and it involves User Account and Appointment modules. **Back-end:** Java 8, Spring Boot, Spring Data, Spring Security, Hibernate, MySQL, Maven, Log4j + +## Configuration + +User-Front reads its database credentials from environment variables: + +| Variable | Required | Default | Purpose | +|---------------|----------|---------|-------------------------------------------| +| `DB_USER` | no | `root` | MySQL user (`spring.datasource.username`) | +| `DB_PASSWORD` | yes | none | MySQL password (`spring.datasource.password`) | + +Startup fails immediately if `DB_PASSWORD` is not set. + +``` +cd UserFront +DB_PASSWORD= mvn spring-boot:run +``` + +For local development you can instead copy `UserFront/application-local.properties.example` to `UserFront/application-local.properties` (git-ignored), fill in your credentials, and run from `UserFront/` with `SPRING_PROFILES_ACTIVE=local`. diff --git a/UserFront/.gitignore b/UserFront/.gitignore index 2af7cefb..dd5f88e0 100644 --- a/UserFront/.gitignore +++ b/UserFront/.gitignore @@ -21,4 +21,7 @@ build/ nbbuild/ dist/ nbdist/ -.nb-gradle/ \ No newline at end of file +.nb-gradle/ + +### Local configuration ### +application-local.properties diff --git a/UserFront/application-local.properties.example b/UserFront/application-local.properties.example new file mode 100644 index 00000000..646ef003 --- /dev/null +++ b/UserFront/application-local.properties.example @@ -0,0 +1,7 @@ +# Local development overrides. +# Copy to application-local.properties (git-ignored) in this directory and start the app +# from here with the "local" profile, e.g.: +# SPRING_PROFILES_ACTIVE=local mvn spring-boot:run +spring.datasource.url = jdbc:mysql://localhost:3306/onlinebanking +spring.datasource.username = root +spring.datasource.password = change-me diff --git a/UserFront/src/main/java/com/userFront/config/DataSourcePasswordCheck.java b/UserFront/src/main/java/com/userFront/config/DataSourcePasswordCheck.java new file mode 100644 index 00000000..fc80f8f4 --- /dev/null +++ b/UserFront/src/main/java/com/userFront/config/DataSourcePasswordCheck.java @@ -0,0 +1,33 @@ +package com.userFront.config; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.context.EnvironmentAware; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +/** + * Aborts startup before any bean is created when the datasource password cannot be resolved, + * instead of letting the literal placeholder reach the database as a password. + */ +@Component +public class DataSourcePasswordCheck implements BeanFactoryPostProcessor, EnvironmentAware { + + private Environment environment; + + @Override + public void setEnvironment(Environment environment) { + this.environment = environment; + } + + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { + try { + environment.getRequiredProperty("spring.datasource.password"); + } catch (IllegalArgumentException | IllegalStateException ex) { + throw new IllegalStateException( + "Datasource password is not configured: set the DB_PASSWORD environment variable", ex); + } + } +} diff --git a/UserFront/src/main/resources/application.properties b/UserFront/src/main/resources/application.properties index d7e04942..012ce27a 100644 --- a/UserFront/src/main/resources/application.properties +++ b/UserFront/src/main/resources/application.properties @@ -7,9 +7,9 @@ # Connection url for the database "netgloo_blog" spring.datasource.url = jdbc:mysql://localhost:3306/onlinebanking -# Username and secret -spring.datasource.username = root -spring.datasource.password = avengers1993 +# Username and secret, supplied via the DB_USER / DB_PASSWORD environment variables +spring.datasource.username = ${DB_USER:root} +spring.datasource.password = ${DB_PASSWORD} # Keep the connection alive if idle for a long time (needed in production) spring.datasource.testWhileIdle = true From 4f465e80a90f2b6e32ce886faf0f2669af87738b Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 30 Sep 2026 16:17:58 +0000 Subject: [PATCH 2/2] COG-1158: clarify DB_PASSWORD requirement in README Co-Authored-By: patrick.bradley --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c0854688..62e3096f 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,9 @@ User-Front reads its database credentials from environment variables: | Variable | Required | Default | Purpose | |---------------|----------|---------|-------------------------------------------| | `DB_USER` | no | `root` | MySQL user (`spring.datasource.username`) | -| `DB_PASSWORD` | yes | none | MySQL password (`spring.datasource.password`) | +| `DB_PASSWORD` | yes* | none | MySQL password (`spring.datasource.password`) | -Startup fails immediately if `DB_PASSWORD` is not set. +\* Required unless `spring.datasource.password` is supplied some other way (e.g. the `local` profile below). Startup fails immediately if no datasource password is configured. ``` cd UserFront