tomcat jndi加密

系统 1353 0


平常我们配置数据源可能都是明文的配置下数据库用户和密码连上数据库就ok,但是有些用户感觉这明文的密码还是很不爽的,那么我们就需要给密码加密了,进入正题: 我的数据源配置是tomcat 目录下面 conf 文件夹下面的 context.xml文件:(这是未加密的配置)

<?xml version="1.0" encoding="UTF-8"?>

<!– The contents of this file will be loaded for each web application –>

<context>

<!– Default set of monitored resources 172.16.5.28:KM–>

<watchedresource>WEB-INF/web.xml</watchedresource>

<resource 

         name="jdbc/test"

         auth="Container"

         type="javax.sql.DataSource"

         maxactive="500"

         maxidle="30"

         maxwait="10000"

         username="test"

         password="test

         driverClassName="oracle.jdbc.OracleDriver"

         url="jdbc:oracle:thin:@localhost:1521:orcl">

</resource>

</context>

然后附件中的文件就派上用场了(encrypt2.bat,commons-dbcp-1.2.2.jar和commons-pool-1.4.jar )

1、进入tomcat的安装目录: tomcatroot\common\lib

2、复制encrypt2.bat和commons-dbcp-1.2.2.jar和commons-pool-1.4.jar 进入该目录

3、进入cmd状态,切换入tomcatroot\common\lib目录 ,非常重要的是需要把webapps下面的各个应用里面的重复的jar删掉也就是要把所有的字母里面的commons-dbcp*.jar和commons-pool*.jar删掉

4、输入encrypt2.bat test (test)还是原密码,界面上会输出:

test 加密后: jAVagnSq2eQ=

test 解密后: test

5、修改context.xml password="jAVagnSq2eQ=" 并注意增加一行: factory="org.apache.commons.dbcp.BasicDataSourceFactory"

那么我们最后的配置就是:

<?xml version="1.0" encoding="UTF-8"?>

<!– The contents of this file will be loaded for each web application –>

<context>

<!– Default set of monitored resources 172.16.5.28:KM–>

<watchedresource>WEB-INF/web.xml</watchedresource>

<resource

           name="jdbc/test"

           auth="Container"

           type="javax.sql.DataSource"

           maxactive="500" maxidle="30"

           maxwait="10000"

           username="test"

           password="jAVagnSq2eQ="

           driverClassName="oracle.jdbc.OracleDriver"

           factory="org.apache.commons.dbcp.BasicDataSourceFactory"              

           url="jdbc:oracle:thin:@localhost:1521:orcl">

</resource>

</context>

好了,重启试试吧

tomcat jndi加密


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论