一、JBoss下配置数据源时,如果密码直接暴露给了系统的操作员或者维护人员,显然就增加了数据库不安全的因素。
<?xml version="1.0" encoding="UTF-8"?> <!-- ===================================================================== --> <!-- --> <!-- JBoss Server Configuration --> <!-- --> <!-- ===================================================================== --> <!-- See http://www.jboss.org/community/wiki/Multiple1PC for information about local-tx-datasource --> <!-- $Id: mssql-ds.xml 97536 2009-12-08 14:05:07Z jesper.pedersen $ --> <!-- ======================================================================--> <!-- New ConnectionManager setup for Microsoft SQL Server 2005 driver --> <!-- Further information about the Microsoft JDBC Driver version 1.1 --> <!-- can be found here: --> <!-- http://msdn2.microsoft.com/en-us/library/aa496082.aspx --> <!-- ===================================================================== --> <datasources> <local-tx-datasource> <jndi-name>MSSQLDS</jndi-name> <connection-url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=MyDatabase</connection-url> <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class> <user-name>admin</user-name> <password>password</password> <!-- sql to call when connection is created <new-connection-sql>some arbitrary sql</new-connection-sql> --> <!-- sql to call on an existing pooled connection when it is obtained from pool <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql> --> <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) --> <metadata> <type-mapping>MS SQLSERVER2000</type-mapping> </metadata> </local-tx-datasource> </datasources>
D:\JBoss\jboss-6.1.0.Final>java -cp client\jboss-logging.jar;lib\jbosssx.jar org.jboss.resource.security.SecureIdentityLoginModule password Encoded password: 5dfc52b51bd35553df8592078de921bc
<?xml version="1.0" encoding="UTF-8"?> <!-- ===================================================================== --> <!-- --> <!-- JBoss Server Configuration --> <!-- --> <!-- ===================================================================== --> <!-- See http://www.jboss.org/community/wiki/Multiple1PC for information about local-tx-datasource --> <!-- $Id: mssql-ds.xml 97536 2009-12-08 14:05:07Z jesper.pedersen $ --> <!-- ======================================================================--> <!-- New ConnectionManager setup for Microsoft SQL Server 2005 driver --> <!-- Further information about the Microsoft JDBC Driver version 1.1 --> <!-- can be found here: --> <!-- http://msdn2.microsoft.com/en-us/library/aa496082.aspx --> <!-- ===================================================================== --> <datasources> <local-tx-datasource> <jndi-name>MSSQLDS</jndi-name> <connection-url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=MyDatabase</connection-url> <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class> <!-- REPLACED WITH security-domain BELOW <user-name>admin</user-name> <password>password</password> --> <security-domain>EncryptDBPassword</security-domain> <!-- sql to call when connection is created <new-connection-sql>some arbitrary sql</new-connection-sql> --> <!-- sql to call on an existing pooled connection when it is obtained from pool <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql> --> <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) --> <metadata> <type-mapping>MS SQLSERVER2000</type-mapping> </metadata> </local-tx-datasource> </datasources>
<?xml version='1.0'?> <!DOCTYPE policy PUBLIC "-//JBoss//DTD JBOSS Security Config 3.0//EN" "http://www.jboss.org/j2ee/dtd/security_config.dtd"> <policy> <!-- Example usage of the SecureIdentityLoginModule --> <application-policy name="EncryptedMySQLDbRealm"> <authentication> <login-module code="org.jboss.resource.security.SecureIdentityLoginModule" flag="required"> <module-option name="username">admin</module-option> <module-option name="password">5dfc52b51bd35553df8592078de921bc</module-option> <module-option name="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MSSQLDS</module-option> </login-module> </authentication> </application-policy> </policy>
<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="org.jboss.security.auth.login.DynamicLoginConfig" name="jboss:service=Test.DynamicLoginConfig"> <attribute name="AuthConfig">META-INF/login-config.xml</attribute> <!-- The service which supports dynamic processing of login-config.xml configurations. --> <depends optional-attribute-name="LoginConfigService">jboss.security:service=XMLLoginConfig</depends> <!-- Optionally specify the security mgr service to use when this service is stopped to flush the auth caches of the domains registered by this service. --> <depends optional-attribute-name="SecurityManagerService">jboss.security:service=JaasSecurityManager</depends> </mbean> </server>
package org.jboss.resource.security; public class SecureIdentityLoginModule { private static String encode(String secret) { return secret; } private static char[] decode(String secret) { System.out.println("Input password: " + secret); return new char[] { '0', '1', '2', '3', '4', '5' }; } }
package org.jboss.resource.security; import java.lang.reflect.Method; /** * Decode the encoded password. * * @author 酒樽舞曲 * */ public class PasswordDecoder { public static void main(String args[]) throws Exception { Class<SecureIdentityLoginModule> cla = SecureIdentityLoginModule.class; Method m = cla.getDeclaredMethod("decode", String.class); m.setAccessible(true); Object obj = m.invoke(null, args[0]); char[] chars = (char[]) obj; System.out.println("Decoded password: " + new String(chars)); } }
D:\JBoss\jboss-6.1.0.Final>java -cp client\jboss-logging.jar;lib\jbosssx.jar org.jboss.resource.security.PasswordDecoder 5dfc52b51bd35553df8592078de921bc Decoded password: password
转载请标明出处:http://blog.csdn.net/w709854369/article/details/7642503