Implementation of UserDatabase that persists
DefaultUserProfile objects to a JDBC DataSource, as might typically be provided by a web
container. This implementation looks up the JDBC DataSource using JNDI.
The JNDI name of the datasource, backing table and mapped columns used
by this class are configured via settings in jspwiki.properties .
Configurable properties are these:
Property |
Default |
Definition |
jspwiki.userdatabase.datasource |
jdbc/UserDatabase |
The JNDI name of the DataSource |
jspwiki.userdatabase.table |
users |
The table that stores the user profiles |
jspwiki.userdatabase.created |
created |
The column containing the profile's creation timestamp |
jspwiki.userdatabase.email |
email |
The column containing the user's e-mail address |
jspwiki.userdatabase.fullName |
full_name |
The column containing the user's full name |
jspwiki.userdatabase.loginName |
login_name |
The column containing the user's login id |
jspwiki.userdatabase.password |
password |
The column containing the user's password |
jspwiki.userdatabase.modified |
modified |
The column containing the profile's last-modified timestamp |
jspwiki.userdatabase.wikiName |
wiki_name |
The column containing the user's wiki name |
jspwiki.userdatabase.roleTable |
roles |
The table that stores user roles. When a new user is created,
a new record is inserted containing user's initial role. The
table will have an ID column whose name and values correspond
to the contents of the user table's login name column. It will
also contain a role column (see next row). |
jspwiki.userdatabase.role |
role |
The column in the role table that stores user roles. When a new user
is created, this column will be populated with the value
Authenticated . Once created, JDBCUserDatabase does not
use this column again; it is provided strictly for the convenience
of container-managed authentication services. |
jspwiki.userdatabase.hashPrefix |
true |
Whether or not to prepend a prefix for the hash algorithm, e.g.,
{SHA} . |
This class hashes passwords using SHA-1. All of the underying SQL commands used by this class are implemented using
prepared statements, so it is immune to SQL injection attacks.
This class is typically used in conjunction with a web container's JNDI resource
factory. For example, Tomcat versions 4 and higher provide a basic JNDI factory
for registering DataSources. To give JSPWiki access to the JNDI resource named
by , you would declare the datasource resource similar to this:
<Context ...>
...
<Resource name="jdbc/UserDatabase" auth="Container"
type="javax.sql.DataSource" username="dbusername" password="dbpassword"
driverClassName="org.hsql.jdbcDriver" url="jdbc:HypersonicSQL:database"
maxActive="8" maxIdle="4"/>
...
</Context>
JDBC driver JARs should be added to Tomcat's common/lib directory.
For more Tomcat 5.5 JNDI configuration examples,
see
http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html.
JDBCUserDatabase commits changes as transactions if the back-end database supports them.
If the database supports transactions, user profile changes are saved
to permanent storage only when the
JDBCUserDatabase.commit() method is called. If the database does not
support transactions, then changes are made immediately (during the
JDBCUserDatabase.save(UserProfile) method), and the
method no-ops. Thus, callers should always call the
method after saving a profile to guarantee that changes are applied.
author: Andrew R. Jaquith since: 2.3 |