Database storage and password issues of Apache James user information: Chen Source: www.zdnet.com.cn visit: Times Joined: 2004-12-14
This article mainly solves two problems: one is how to store James's user information into the database, and how to handle password issues when JAMES twice is developed. This article is for users who have experience in James. For James's initiator, please read my article "Apache James Getting Started". 1. James Introduction Apache James (Java Apache Mail Enterprise Server) is one of the subcommets of the Apache organization, which is fully developed, implemented in various mail related protocols such as SMTP, POP3 and NNTP. James is also an email application platform that can be extended through the MAILET, such as Mail2Sms, Mail2fax, etc. James provides a relatively complete configuration scheme, especially for mail content storage and user information storage portions, can be saved in files, databases, or other media. JAMES is stable, configurable, or open source project, all source code does not have copyright issues, so the application in the project is increasingly wide, and now the common version is 2.3, but the latest version 2.3 has been launched, in this article, we It will still be used as James2.1 as a introduction blue. Second, a hypothetical project assumes that I want to use James as a mail server, develop a web-based mail system, just like 263.net, 163.net, require online registration, online send and receive mail. By default, the user information of James is stored in the text. Although it has been added, since the text archive is insufficient, it is not convenient for query and corresponding processing. Fortunately, James provides a variety of user information storage schemes such as database storage, LDAP storage, etc. Here we will use the Database Storage as an example, explain the management of user information, and the database uses mysql. Of course, you can also use LDAP, such as free OpenLDAP, very powerful. Third, the user information of user information The user information of JAMES mail users is saved in the apps / james / var / users directory, and the user information can be saved to the database by modifying the configuration file apps / james / sar-inf / config.xml. The configuration method is as follows: Step 1: Newly burse a database mail, user name root, password is empty in MySQL; Step 2: Open config.xml, find
package org.apache.james.userrepository; ...... / ** * Method to verify passwords * * @param pass the String that is claimed to be the password for this user * @return true if the hash of pass with the current algorithm. . matches * the stored hash * / public boolean verifyPassword (String pass) {try {String hashGuess = DigestUtil.digestString (pass, algorithm); return hashedPassword.equals (hashGuess);} catch (NoSuchAlgorithmException nsae) {throw new RuntimeException ( " Security error: " nsae);}} / ** * Sets new password from String No checks made on guessability of * password * * @param newPass the String that is the new password * @return true if newPass successfuly hashed... * / Public boolean setPassword (String newpass) {Try {HashedPassword = Digestutil.digestString (newpass, algorithm); return true;} catch (nosuchalithmexception nsae) { Throw New RuntimeException ("Security Error:" NSAE);}} ... The first method verifyPassword () is used to do password authentication, the incoming parameters are the plain text password, via the Digestutil.Digeststring () method, converted into confidentiality CD, then compare the comparison result with the password in the database. Note that the Digestutil.DigestString () method here is also mentioned later. The second method setPassword () is used for password conversion, converting clear text into ciphertext, which is also the Digestutil.DigestString () method. Talking about it, I believe you should know how to make password conversion and password authentication in your own program! In fact, it is not to write a SHA encryption algorithm. Since James has provided this feature, you call it. There is also a situation, developers need to save passwords in the database, so you don't have to convert passwords in your own program, and when multiple application systems use a unified user model, it is best to have only one user instance. To achieve this demand, you can only modify the James source code, change the verifypassword () method and setpassword ():