Best way define important credentials in spring boot

Abhishek saini picture Abhishek saini · Jun 19, 2018 · Viewed 7k times · Source

When using Spring Boot application we use different application.properties files according to different environments.

We put important credentials like: database configurations, server IPs, admin username/password and so on.

I am worrying about what would happen if someone would obtain our application properties and get all important details.

Is there any good approach to put important credentials somewhere and obtain them in our Spring Boot application based on environment?

Answer

Halayem Anis picture Halayem Anis · Jun 19, 2018

Many techniques

  • Using tokens replacement (maven replacor)

    application.properties spring.datasource.password=#MY_DB_PASSWORD#
    tokens.properties #MY_DB_PASSWORD#=SECRET_PASSWORD

    where tokens.properties has an access protection

  • Using environment variable
    mvn spring-boot:run -Dspring.datasource.password=SECRET_PASSWORD

    or simply
    spring.datasource.password=${myDbPasswordEnv}

  • Using Jaspyt to encrypt your properties