如何在apache BasicDataSource中使用加密密码? [英] How to use encrypted password in apache BasicDataSource?
问题描述
[配置xml是数据源,它正在创建dbcp.BasicDataSource的对象]
现在,在ant目标之后,是否有可能以加密形式复制密码。听说Jasypt可以做到!直到现在我还没有尝试过。但是,这个问题并没有结束。 BasicDataSource不接受加密密码。有没有替代BasicDatasource。
FYI:我正在使用Spring,如果这很重要。
通过扩展现有任务复制
(负责文件复制)来创建新任务。通过扩展 FilterSet
(负责过滤令牌)创建一个新类型。
请参阅以下代码:
如何为蚂蚁任务创建嵌套元素?
build.xml
< target name =encrypted-copy >
< CopyEncrypted todir =dist / xyz / configoverwrite =true>
< fileset dir =config/>
< encryptionAwareFilterSet>
< filtersfile file =conf / properties / blah-blah.properties/>
< / encryptionAwareFilterSet>
< / CopyEncrypted>
< / target>
blah-blah.properties
property1 = value1
property2 = value2
PASSWORD = ^& YUII %%& *(
USERNAME = rjuyal
CONNECTION_URL = ...
someotherproperty = value
配置xml
< bean id =dataSource
class =com.xyz.datasource.EncryptionAwareDataSource
destroy-method =closeautowire =byName>
< property name =driverClassName>
< value> com.ibm.db2.jcc.DB2Driver< /值>
< / property>
< property name =url>
< value> @ CONNECTION_URL @< / value>
< / property>
< property name =username>
< value> @ USERNAME @< / value>
< / property>
< property name =password >
< value> @ PASSWORD @< /值GT;
< / property>
< property name =poolPreparedStatements>
< value> true< / value>
< / property>
< property name =maxActive>
< value> 10< / value>
< / property>
< property name =maxIdle>
< value> 10< / value>
< / property>
< / bean>
...
...
...
执行目标后,xml将复制到属性文件中的值。密码将被加密。
这将处理加密密码。
EncryptionAwareDataSource
public class EncryptionAwareDataSource extends BasicDataSource {
@Override
public synchronized void setPassword(String password){
super.setPassword(Encryptor.getDecryptedValue(password));
}
}
那个'全部')
At present i am keeping the password [ unencrypted ] in a property file. This password get placed as is in the configuration xml using ant.
[ The configuration xml is for datasource, it is creating the object of dbcp.BasicDataSource ]
Now, is it possible that after the ant target the password is copied in encrypted form. Heard the Jasypt can do that! Till now i haven't tried this. But, the problem doesn't end here. BasicDataSource do not accept encrypted password. Is there any replacement for BasicDatasource.
FYI: I am using Spring, if that matters.
Create a new task by extending existing task Copy
( responsible for file-copy ). Create a new type by extending FilterSet
( responsible for filtering of tokens ).
see the code here:-
How to create nested element for ant task?
build.xml
<target name="encrypted-copy" >
<CopyEncrypted todir="dist/xyz/config" overwrite="true">
<fileset dir="config"/>
<encryptionAwareFilterSet>
<filtersfile file="conf/properties/blah-blah.properties" />
</encryptionAwareFilterSet>
</CopyEncrypted>
</target>
blah-blah.properties
property1=value1
property2=value2
PASSWORD=^&YUII%%&*(
USERNAME=rjuyal
CONNECTION_URL=...
someotherproperty=value
configuration xml
<bean id="dataSource"
class="com.xyz.datasource.EncryptionAwareDataSource"
destroy-method="close" autowire="byName">
<property name="driverClassName">
<value>com.ibm.db2.jcc.DB2Driver</value>
</property>
<property name="url">
<value>@CONNECTION_URL@</value>
</property>
<property name="username">
<value>@USERNAME@</value>
</property>
<property name="password">
<value>@PASSWORD@</value>
</property>
<property name="poolPreparedStatements">
<value>true</value>
</property>
<property name="maxActive">
<value>10</value>
</property>
<property name="maxIdle">
<value>10</value>
</property>
</bean>
...
...
...
After the execution of the target the xml is copied with values from properties file. Password will be encrypted.
This will handle the encrypted password. EncryptionAwareDataSource
public class EncryptionAwareDataSource extends BasicDataSource{
@Override
public synchronized void setPassword(String password) {
super.setPassword(Encryptor.getDecryptedValue( password ));
}
}
That' all ;)
这篇关于如何在apache BasicDataSource中使用加密密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!