Best way define important credentials in spring boot

Abhishek saini :

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?

Halayem Anis :

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=36247&siteId=1