1.修改数据源文件jtds-ds.xml
<datasources> <local-tx-datasource> <jndi-name>MSSQLDS</jndi-name> <connection-url>jdbc:jtds:sqlserver://ip地址:端口/数据库名;tds=8.0;lastupdatecount=true</connection-url> <driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class> <security-domain>EncryptDBPassword</security-domain> <!-- sql to call on an existing pooled connection when it is obtained from pool --> <check-valid-connection-sql>SELECT 1</check-valid-connection-sql> </local-tx-datasource> </datasources>
2.接着我们修改server\default\conf\login-config.xml文件,加上下面这一段配置文件
<application-policy name="EncryptDBPassword"> <authentication> <login-module code="org.jboss.resource.security.SecureIdentityLoginModule" flag="required"> <module-option name="username">userName</module-option> <module-option name="password">-7c9065f142ec1c019b95c743bfc0fde2</module-option> <module-option name="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MSSQLDS</module-option> </login-module> </authentication> </application-policy>
3.密文生成工具
在jboss中找到applet.jar,jbosssx.jar,将这两个文件放到一个文件夹里,在cmd控制台,进入该目录,输入:java -cp "jbosssx.jar;applet.jar" org.jboss.resource.security.SecureIdentityLoginModule root
这里的root是我们想要加密的密码,Encoded password: 6f8e652f571678f2 红色就是加密后的密码;