how to override JndiObjectFactoryBean in spring and set decrypted password in java

隐身守侯 提交于 2019-12-01 12:01:48

问题


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.

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>

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.


回答1:


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.

Thanks.



来源:https://stackoverflow.com/questions/32387651/how-to-override-jndiobjectfactorybean-in-spring-and-set-decrypted-password-in-ja

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!