Alex
Alex

Reputation: 133

encrypting mongo password in datasource definition using springboot

I'm using spring-boot application which has connection to a Mongo DB. The mongo data-source configured in the application.properties file:

spring.data.mongodb.uri=mongodb://my_user:my_password@mongo_host:37017/mongo_db

I would like to encrypt my_password part of the datasource. Is there out of the box solution for that? Thanks

Upvotes: 1

Views: 4157

Answers (2)

shabinjo
shabinjo

Reputation: 1561

Since it is not resolving encrypted value from url, we can put it in it's own property and then reference that property in the url.

spring.data.mongodb.password=ENC(xIZhIV7nvOv5LqHfAKnvmjhyeecOT0lO)

spring.data.mongodb.uri=mongodb://user:${spring.data.mongodb.password}@mongo1.example.com:12345,mongo2.example.com:12345/mydb?replicaSet=rsdb

Upvotes: 2

Alex
Alex

Reputation: 133

I found jasypt-spring-boot project which does exactly what I need.

Upvotes: 1

Related Questions