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.
JPA Ticket Registry
The JPA Ticket Registry allows CAS to store client authenticated state data (tickets) in a database back-end such as MySQL.
Usage Warning!
Using a RDBMS as the back-end persistence choice for Ticket Registry state management is a fairly unnecessary and complicated process. Ticket registries generally do not need the durability that comes with RDBMS and unless you are already outfitted with clustered RDBMS technology and the resources to manage it, the complexity is likely not worth the trouble. Given the proliferation of hardware virtualization and the redundancy and vertical scaling they often provide, more suitable recommendation would be the default in-memory ticket registry for a single node CAS deployment and distributed cache-based registries for higher availability.
Configuration
Adjust the src/main/webapp/WEB-INF/spring-configuration/ticketRegistry.xml with the following:
The above snippet assumes that data source information and connection details are defined.
Configure other JPA dependencies:
In the pom.xml file of the Maven overlay, adjust for the following dependencies:
Cleaner Locking Strategy
The above shows a JPA 2.0 implementation of an exclusive, non-reentrant lock, JpaLockingStrategy, to be used with the JPA-backed ticket registry.
This will configure the cleaner with the following defaults:
tableName = “LOCKS”
uniqueIdColumnName = “UNIQUE_ID”
applicationIdColumnName = “APPLICATION_ID”
expirationDataColumnName = “EXPIRATION_DATE”
platform = SQL92
lockTimeout = 3600 (1 hour)
Database Configuration
JDBC Driver
CAS must have access to the appropriate JDBC driver for the database. Once you have obtained the appropriate driver and configured the data source, place the JAR inside the lib directory of your web server environment (i.e. $TOMCAT_HOME/lib)
Schema
If the user has sufficient privileges on start up, the database tables should be created. The database user MUST have CREATE/ALTER privileges to take advantage of automatic schema generation and schema updates.
Deadlocks
The Hibernate SchemaExport DDL creation tool may fail to create two very import indices when generating the ticket tables. The absence of these indices dramatically increases the potential for database deadlocks under load.
If the indices were not created you should manually create them before placing your CAS configuration into a production environment.
To review indices, you may use the following MYSQL-based sample code below:
To create indices that are missing, you may use the following sample code below:
MYSQL
ORACLE
Ticket Cleanup
The use JpaLockingStrategy is strongly recommended for HA environments where multiple nodes are attempting ticket cleanup on a shared database. JpaLockingStrategy can auto-generate the schema for the target platform. A representative schema is provided below that applies to PostgreSQL:
Platform-Specific Issues
The exact DDL to create the LOCKS table may differ from the above. For example, on Oracle platforms the `expiration_date` column must be of type `DAT`E. Use the `JpaLockingStrategy` which can create and update the schema automatically to avoid platform-specific schema issues.
Connection Pooling
The following configuration parameters are provided for information only and may serve as a reasonable
starting point for configuring a production database connection pool.
The following maven dependency for the library must be included in your Maven overlay:
Platform Considerations
MySQL
Use InnoDB Tables
The use of InnoDB tables is strongly recommended for the MySQL platform for a couple reasons:
InnoDB provides referential integrity that is helpful for preventing orphaned records in ticket tables.
Provides better locking semantics (e.g. support for SELECT … FOR UPDATE) than the default MyISAM table type.
InnoDB tables are easily specified via the use of the following Hibernate dialect:
BLOB vs LONGBLOB
Hibernate on recent versions of MySQL (e.g. 5.1) properly maps the @Lob JPA annotation onto type LONGBLOB, which is very important since these fields commonly store serialized graphs of Java objects that grow proportionally with CAS SSO session lifetime. Under some circumstances, Hibernate may treat these columns as type BLOB, which have storage limits that are easily exceeded. It is recommended that the generated schema be reviewed and any BLOB type columns be converted to LONGBLOB.
The following MySQL statement would change this SERVICES_GRANTED_ACCESS_TO column’s type to LONGBLOB:
Case Sensitive Schema
It may necessary to force lowercase schema names in the MySQL configuration: