Passing encrypted properties to spring context

I never seen this but I wondering if somebody has come across. Having a web server which access a database. I want to pass the database password encrypted and have spring context decrypting it before setting the datasource. I know the spring security can do some of this like using a salt file in the web server, etc.

The challenge here is that I don't want to give a clear user,password,url to the web server team. Just an encrypted password and have spring decrypted before using it.

Is there something like this already? I know I could code something but is it already done?

Thanks

Answers


By using an org.jasypt.properties.EncryptableProperties object, an application would be able to correctly read and use a .properties file like this:

 datasource.driver=com.mysql.jdbc.Driver
 datasource.url=jdbc:mysql://localhost/reportsdb
 datasource.username=reportsUser
 datasource.password=ENC(G6N718UuyPE5bHyWKyuLQSm02auQPUtm)

Note that the database password is encrypted (in fact, any other property could also be encrypted, be it related with database configuration or not).

More information :

http://www.jasypt.org/encrypting-configuration.html


I actually found exactly what I was looking for in this thread:

How to use encrypted password in apache BasicDataSource? Here are the details from jasyp http://www.jasypt.org/spring3.html


This problem and solution to it is explained here..(link)

db.Properties.

#driverClassName=oracle.jdbc.driver.OracleDriver
#url=jdbc:oracle:thin:@localhost:1521:XE
#username=ITEM_INVENTORY
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/ITEM_INVENTORY?zeroDateTimeBehavior=convertToNull

username=root
  1. Encrypt db.Properties

      ##password=cGFzc3dvcmQ=
      password=cm9vdA==
    

The spring beans configuration for the datasource would look like this (here you may use only password part)

  1. spring-beans.xml

    <bean id="dataSource" destroy-method="close"  class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="db#[driverClassName]" />
        <property name="url" value="db#[url]" />
        <property name="username" value="db#[username]" />
        <property name="password" value="encryptedDb#[password]" />
     </bean>  
     <bean id="dbPropertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
     <property name="locations">  
         <list>  
           <value>classpath:db.properties</value>  
         </list>  
      </property>  
         <property name="placeholderPrefix" value="db#[" />
         <property name="placeholderSuffix" value="]" />  
      </bean>  
      <bean id="encryptedDbPropertyPlaceholder"  class="com.inventory.api.util.DecryptPropertyConfigurer">  
        <property name="locations">  
           <list>  
              <value>classpath:encryped_db.properties</value>  
           </list>  
        </property>  
        <property name="placeholderPrefix" value="encryptedDb#[" />  
        <property name="placeholderSuffix" value="]" /&gt;  
      </bean> 
    

And so on.. please refer given link for more information..


Need Your Help

Numpy bincount() with floats

python numpy

I am trying to get a bincount of a numpy array which is of the float type:

How to check when HealthKit function has been completed (Swift)

ios swift function health-kit completionhandler

Well, the title really says it all, and I haven't been able to find an answer anywhere that works for me so I am turning to StackOverFlow. I am trying to get a users step count and assign that valu...