Data Source password encryption in JBoss

Source: Internet
Author: User

Data Source password encryption in JBoss
Author: Xiao Hongye 2007.4.7

1. First, let's look at a common data source configuration file.

Code
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Datasources>
  3. <Local-TX-datasource>
  4. <JNDI-Name> mysqlds </JNDI-Name> // JNDI name
  5. <Use-Java-context> false </use-Java-context>
  6. <Connection-URL> JDBC: mysql: // 10.16.175.20.: 3306/test </connection-URL> // URL
  7. <Driver-class> com. MySQL. JDBC. Driver </driver-class> // driver
  8. <User-Name> root </user-Name> // User Name
  9. <Password> 123456 </password> // Password
  10. <Exception-sorter-class-Name>
  11. Org. JBoss. Resource. Adapter. JDBC. Vendor. mysqlexceptionsorter
  12. </Exception-sorter-class-Name>
  13. <Metadata>
  14. <Type-mapping> mysql </type-mapping>
  15. </Metadata>
  16. </Local-TX-datasource>
  17. </Datasources>

 

Let's take a look at this file. Both the user name and password are stored in plain text, which brings great security to the system. Therefore, we need to add a password for our plaintext password. This is the purpose of this Article.
2. Speaking of password encryption, here we use a class org. JBoss. Resource. Security. sedureidentityloginmodule under JBoss to see how we can use it to encrypt our passwords.

First look at an example of configuring the data source (mysql-ds.xml ):

Code
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Datasources>
  3. <Local-TX-datasource>
  4. <JNDI-Name> mysqlds </JNDI-Name>
  5. <Use-Java-context> false </use-Java-context>
  6. <Connection-URL> JDBC: mysql: // 192.168.1.91: 3306/atteam </connection-URL>
  7. <Driver-class> com. MySQL. JDBC. Driver </driver-class>
  8. <Security-domain> encryptdbpassword </security-domain> // here you do not need to write your user name and password, we can do something in the login-config.xml, it is OK
  9. <Exception-sorter-class-Name> org. JBoss. Resource. Adapter. JDBC. Vendor. mysqlexceptionsorter </exception-sorter-class-Name>
  10. <Metadata>
  11. <Type-mapping> mysql </type-mapping>
  12. </Metadata>
  13. </Local-TX-datasource>
  14. </Datasources>

 

Next we modify the server/default/CONF/login-config.xml file, add the following configuration file

 

Code
  1. <Application-Policy Name = "encryptdbpassword"> // The name here should be the security-domain string you wrote When configuring the data source.
  2. <Authentication>
  3. <Login-module code = "org. JBoss. Resource. Security. secureidentityloginmodule"
  4. Flag = "required">
  5. <Module-option name = "username"> test </Module-option> // User Name of the database
  6. <Module-option name = "password"> 64c5fd2979a86168 </Module-option> // password of the database, which is encrypted.
  7. <Module-option name = "managedconnectionfactoryname"> JBoss. JCA: service = localtxcm, name = mysqlds </Module-option>
  8. // Note that the name is the same as the JNDI-name of your data source. Here is mysqlds
  9. </Login-module>
  10. </Authentication>
  11. </Application-Policy>

 

3. To add, where did the encrypted password come from)

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

Write your own path and the password you want to encrypt. The password I want to encrypt here is 123456. After encryption, it is 64c5fd2979a86168.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.