Jboss数据源文件密码加密

 数据源文件普通写法

<?xml version="1.0" encoding="UTF-8"?> 
<datasources> 
  <local-tx-datasource> 
    <jndi-name>MySqlDS</jndi-name> //jndi名字 
    <use-java-context>false</use-java-context> 
    <connection-url>jdbc:mysql://10.16.175.137:3306/test</connection-url> //URL地址 
    <driver-class>com.mysql.jdbc.Driver</driver-class> //驱动 
    <user-name>root</user-name> //用户名 
    <password>123456</password> //密码 
    <exception-sorter-class-name> 
        org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter 
       </exception-sorter-class-name> 
      <metadata> 
       <type-mapping>mySQL</type-mapping> 
    </metadata> 
  </local-tx-datasource> 
</datasources>

加密方法:

 

1,用JBoss下的类org.jboss.resource.security.SedureIdentityLoginModule,加密

 

java -cp "D:\TDdownload\jboss-4.2.0.CR1\jboss-4.2.0.CR1\lib\jboss-jmx.jar;D:\TDdownload\jboss-4.2.0.CR1\jboss-4.2.0.CR1\lib\jboss-common.jar;D:\TDdownload\jboss-4.2.0.CR1\jboss-4.2.0.CR1\server\default\lib\jboss-jca.jar;D:\TDdownload\jboss-4.2.0.CR1\jboss-4.2.0.CR1\server\default\lib\jbosssx.jar" org.jboss.resource.security.SecureIdentityLoginModule 123456

 

Encoded password: 64c5fd2979a86168

 

2,修改server\default\conf\login-config.xml文件,加上下面这一段配置文件

<application-policy name="EncryptDBPassword"> //这里的name应该是你在配置数据源时写的security-domain里的字符串
      <authentication>
        <login-module code="org.jboss.resource.security.SecureIdentityLoginModule"
          flag="required">
          <module-option name="username">test</module-option> //数据库的用户名
          <module-option name="password">64c5fd2979a86168</module-option> //数据库的密码,不过是加密过的了
          <module-option name="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MySqlDS</module-option>
         //注意name等于你的数据源的jndi-name,这里是MySqlDS
        </login-module>
      </authentication>
  </application-policy>

 

3,加密后的数据源配置

<?xml version="1.0" encoding="UTF-8"?> 
<datasources> 
  <local-tx-datasource> 
    <jndi-name>MySqlDS</jndi-name> 
    <use-java-context>false</use-java-context> 
    <connection-url>jdbc:mysql://192.168.1.91:3306/atteam</connection-url> 
    <driver-class>com.mysql.jdbc.Driver</driver-class> 
    <security-domain>EncryptDBPassword</security-domain>//这里不用写上你的用户名与密码了,我们可以在login-config.xml里做点手脚,就OK了 
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name> 
    <metadata> 
       <type-mapping>mySQL</type-mapping> 
    </metadata> 
  </local-tx-datasource> 
</datasources>

 

大功告成!

你可能感兴趣的:(mysql,xml,jboss,jdbc,Security)