简体   繁体   English

Spring应用程序上下文加密

[英]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. 您需要使用propertyPlaceHolder外部化属性。 Once you do that you can use the Jasypt version of property place holder that supports encryption. 完成后,您可以使用支持加密的Jasypt版本的属性占位符。

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. 您可以改为创建jndi连接。 In tomcat context.xml for example you add. 例如,在tomcat context.xml中添加。 That way you do not store any information in the application or properties file. 这样,您就不会在应用程序或属性文件中存储任何信息。 Offcourse you have to set permissions to context.xml... 在Offcourse你必须设置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"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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