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. 

Set the properties variable


file as follows: (such as values of property variables will not visible directly, rather saved in bashrc and retrieved from the same).

1- Open bashrc file:
vim  ~/.bashrc

2- export the variables that need to be set into bashrc 
export MAIL_HOST="hostName"
export MAIL_PASSWORD="Password"

3- Save the file

4- Reflect the changes done in bashrc   
source  ~/.bashrc

5- Check from terminal whether variable is set to bashrc or not
if [ -z "$MAIL_HOST" ]
    echo "not defined"
    echo "defined"

If MAIL_HOST is properly set to bashrc then the output will be defined else not defined or in another case respective mail host will be printed.

6- Access the configuration set into bashrc to properties file: = ${MAIL_HOST}
spring.mail.username =${MAIL_USERNAME}
spring.mail.password =${MAIL_PASSWORD} = true = 587 = true = false



Benefits of approach:
When we set the information in
bashrc we do not require to set multiple profiles. Since different profile may use different configuration hence we can simply set the properties required for development in development bashrc, production in production's bashrc and so on..
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 bashrc sometime one may require to source the bashrc from the project location. So before running the application, it is required to source the bashrc from project location as follows: 

source ~/.bashrc




Request for Proposal

Recaptcha is required.

Sending message..