You are viewing the development documentation for the Apereo CAS server. The
functionality presented
here is not officially released yet.
This is a work in progress and will be continually updated as development moves forward. To view
the documentation for a specific Apereo CAS server release, please choose an appropriate version.
The release schedule is also available here.
Database Authentication
Database authentication components are enabled by including the following dependencies in the Maven WAR overlay:
Connection Pooling
All database authentication components require a DataSource for acquiring connections to the underlying database.
The use of connection pooling is strongly recommended, and the c3p0 library
is a good choice that we discuss here.
Tomcat JDBC Pool is another competent alternative.
Note that the connection pool dependency mentioned above should be modified according to the choice of connection pool
components.
Pooled Data Source Example
A bean named dataSource must be defined for CAS components that use a database. A bean like the following should be
defined in deployerConfigContext.xml.
The following properties may be used as a starting point for connection pool configuration/tuning.
Database Components
CAS provides the followng components to accommodate different database authentication needs.
QueryDatabaseAuthenticationHandler
Authenticates a user by comparing the (hashed) user password against the password on record determined by a
configurable database query. QueryDatabaseAuthenticationHandler is by far the most flexible and easiest to
configure for anyone proficient with SQL, but SearchModeSearchDatabaseAuthenticationHandler provides an alternative
for simple queries based solely on username and password and builds the SQL query using straightforward inputs.
The following database schema for user data is assumed in the following two examples that leverage SQL queries
to authenticate users.
The following example uses an MD5 hash algorithm and searches exclusively for active users.
SearchModeSearchDatabaseAuthenticationHandler
Searches for a user record by querying against a username and (hashed) password; the user is authenticated if at
least one result is found.
The following example uses a SHA1 hash algorithm to authenticate users.
BindModeSearchDatabaseAuthenticationHandler
Authenticates a user by attempting to create a database connection using the username and (hashed) password.
The following example does not perform any password encoding since most JDBC drivers natively encode plaintext
passwords to the appropriate format required by the underlying database. Note authentication is equivalent to the
ability to establish a connection with username/password credentials. This handler is the easiest to configure
(usually none required), but least flexible, of the database authentication components.
QueryAndEncodeDatabaseAuthenticationHandler
A JDBC querying handler that will pull back the password and
the private salt value for a user and validate the encoded
password using the public salt value. Assumes everything
is inside the same database table. Supports settings for
number of iterations as well as private salt.
This password encoding method, combines the private Salt and the public salt which it prepends to the password before hashing.
If multiple iterations are used, the bytecode Hash of the first iteration is rehashed without the salt values.
The final hash is converted to Hex before comparing it to the database value.