如何在Apache中的BasicDataSource使用加密的密码? [英] How to use encrypted password in apache BasicDataSource?

查看:2010
本文介绍了如何在Apache中的BasicDataSource使用加密的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在present我保持在属性文件中的密码[加密]。此密码得到安置的是在配置XML使用蚂蚁。结果
 [XML配置为数据源,它是创造dbcp.BasicDataSource对象]

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 ]

现在,是有可能,Ant目标后,密码被加密形式复制。听到Jasypt能做到这一点!到现在我还没有尝试过这一点。但是,问题并没有到此结束。的BasicDataSource不接受加密的口令。有没有替代的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:我使用的春天,如果该事项

FYI: I am using Spring, if that matters.

推荐答案

通过扩展现有任务复制(负责文件复制)创建一个新的任务。通过扩展创建一个新的类型 FilterSet (负责令牌的过滤)。结果
见code在这里: -
<一href=\"http://stackoverflow.com/questions/3657910/how-to-create-nested-element-for-ant-task\">http://stackoverflow.com/questions/3657910/how-to-create-nested-element-for-ant-task

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:- http://stackoverflow.com/questions/3657910/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

配置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>
...
...
...

目标执行之后的XML复制从属性文件中的值。密码将被加密。

After the execution of the target the xml is copied with values from properties file. Password will be encrypted.

这将处理加密的密码。
EncryptionAwareDataSource

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆