如何在spring中覆盖JndiObjectFactoryBean并在java中设置解密密码 [英] how to override JndiObjectFactoryBean in spring and set decrypted password in java

查看:1495
本文介绍了如何在spring中覆盖JndiObjectFactoryBean并在java中设置解密密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在tomcat中有一个数据源,其密码是使用某种算法加密的,我想在与DB建立连接时解密。

I have a datasource in tomcat which has password that is encrypted using some algorithm and I want to decrypt the same when i establish connection with DB.

以下是我的spring配置代码

Following is my spring config code

<!--<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="${jdbc.jndiName}"/>
</bean>-->

<bean id="dataSource" class="my.app.util.EncryptedDataSource">
    <property name="jndiName" value="${jdbc.jndiName}"/>
</bean>

上面的bean是一个自定义的bean,它扩展了JndiObjectFactoryBean

The above bean is a custom one that extends the JndiObjectFactoryBean

public class EncryptedDataSource extends JndiObjectFactoryBean{ ... }

我应该在这里做什么来获取加密密码并将其设置回来。
我有我的解密算法,但我不确定哪种超级方法会获取我可以重新设置的密码。

What should I do here to get the encryted password and set it back. I have my decrytion algorithm with me but I am not sure which super class method will fetch me the password that i can set back again.

请提示,我已经搜索并尝试了很多。

Please suggest, i have search and tried a lot.

推荐答案

我想通了,而不是覆盖JndiBeanFacotry,我使用了tomcat数据源factory属性,它允许您拥有一个自定义资源工厂类,每次实例化数据源查找时都会调用它。

I figured it out, Instead of overriding the JndiBeanFacotry, I used the tomcat data source "factory" property, it allows you to have a custom resource factory class that gets called every time data source lookup is instantiated.

下面的链接指定了逐步配置,

Below link specifies step by step configuration,

http ://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html

添加自定义资源工厂部分强调如何写一个简单的自定义资源工厂。

"Adding Custom Resource Factories" section emphasises how to write a simple custom resource factory.

谢谢。

这篇关于如何在spring中覆盖JndiObjectFactoryBean并在java中设置解密密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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