简体   繁体   中英

Spring application context encryption

Is there any way that I could encrypt the application context entries, for example:

<bean id="securityDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://192.168.0.1/schemaname?useUnicode=true&amp;characterEncoding=utf-8"/>
    <property name="username" value="{this should be encrypted}"/>
    <property name="password" value="{this should be encrypted}"/>     
</bean> 

What I want to do is to encrypt the username & password.

You will need to externalize the properties using the propertyPlaceHolder. Once you do that you can use the Jasypt version of property place holder that supports encryption.

As fare as i know there is no Encrytion.


But you could externalize the properties, or the complete data source in the application server context.

You could create a jndi connection instead. In tomcat context.xml for example you add. That way you do not store any information in the application or properties file. Offcourse you have to set permissions to context.xml...

<Resource name="jdbc/[YourDatabaseName]" 
              auth="Container"
              type="javax.sql.DataSource" 
              username="[DatabaseUsername]" 
              password="[DatabasePassword]"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://[yourserver]:3306/[yourapplication]"
              maxActive="15" 
              maxIdle="3"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM