Tomcat jndi 加密

平常我們配置數據源可能都是明文的配置下數據庫用戶和密碼連上數據庫就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>

發佈了47 篇原創文章 · 獲贊 21 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章