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

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

问题描述

目前我将密码 [未加密] 保存在一个属性文件中.此密码使用 ant.
按原样放置在配置 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 ]

现在,是否有可能在蚂蚁目标之后以加密形式复制密码.听说 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.

仅供参考:如果这很重要,我正在使用 Spring.

FYI: I am using Spring, if that matters.

推荐答案

通过扩展现有任务Copy来创建一个新任务(负责文件复制).通过扩展 FilterSet(负责过滤令牌)创建一个新类型.
请参阅此处的代码:-如何为蚂蚁任务创建嵌套元素?

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

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

public class EncryptionAwareDataSource extends BasicDataSource{
    @Override
    public synchronized void setPassword(String password) {     
        super.setPassword(Encryptor.getDecryptedValue( password ));
    }
}

<小时>

这一切;)


That' all ;)

这篇关于如何在 apache BasicDataSource 中使用加密密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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