Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`) |
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
| `DB_PASSWORD` | yes* | none | MySQL password (`spring.datasource.password`) |

\* 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
DB_PASSWORD=<your-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`.
5 changes: 4 additions & 1 deletion UserFront/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ build/
nbbuild/
dist/
nbdist/
.nb-gradle/
.nb-gradle/

### Local configuration ###
application-local.properties
7 changes: 7 additions & 0 deletions UserFront/application-local.properties.example
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
6 changes: 3 additions & 3 deletions UserFront/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down