Getting The Properties Variable Values From bashrc File
Posted By : Ekesh Bahuguna | 29-Jun-2018
Need: Properties file may contain sensitive information like password, emailed etc. If such information is defined in the properties file, anyone who has access to our code can know server location, email, password etc.
Solution:
Set the properties variable
file as follows: (such as values of property variables will not visible directly, rather saved in
1- Open
vim ~/.bashrc
2- export the variables that need to be set into
export MAIL_HOST="hostName"
export MAIL_USERNAME="
export MAIL_PASSWORD="Password"
3- Save the file
4- Reflect the changes done in
source ~/.bashrc
5- Check from terminal whether
if [ -z "$MAIL_HOST" ]
then
echo "not defined"
else
echo "defined"
fi
(or)
echo $MAIL_HOST
If MAIL_HOST is properly set to
6- Access the configuration set into
spring.mail.host = ${MAIL_HOST}
spring.mail.username =${MAIL_USERNAME}
spring.mail.password =${MAIL_PASSWORD}
spring.mail.properties.mail.smtp.auth = true
spring.mail.properties.mail.smtp.socketFactory.port = 587
spring.mail.properties.mail.smtp.starttls.enable = true
spring.mail.properties.mail.smtp.socketFactory.fallback = false
Benefits of approach:
When we set the information
This approach reduces the code for setting multiple profiles. Moreover, this is a secure way to access sensitive information. Now if anyone has access to our code is not eligible to access our security details such as email and password.
Note: To reflect the changes done in
source ~/.bashrc
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Ekesh Bahuguna
Ekesh is Java Developer. Along with that he is good in linux, c, networking and competitive programming. He love to answer over Quora.