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 relational database as the back-end persistence choice for ticket registry state management is a fairly unnecessary and complicated process. Unless you are already outfitted with clustered database technology and the resources to manage it, the complexity is likely not worth the trouble.

Support is enabled by adding the following module into the overlay:

implementation "org.apereo.cas:cas-server-support-jpa-ticket-registry:${project.'cas.version'}"
<dependency>
  <groupId>org.apereo.cas</groupId>
  <artifactId>cas-server-support-jpa-ticket-registry</artifactId>
  <version>${cas.version}</version>
</dependency>
dependencyManagement {
  imports {
    mavenBom "org.apereo.cas:cas-server-support-bom:${project.'cas.version'}"
  }
}

dependencies {  
  implementation "org.apereo.cas:cas-server-support-jpa-ticket-registry"
}

Configuration

The following settings and properties are available from the CAS configuration catalog:

The configuration settings listed below are tagged as Required in the CAS configuration metadata. This flag indicates that the presence of the setting is not strictly necessary in the end-user CAS configuration, because a default value may be assigned or the feature in question may not be immediately intended for use. You may want to own the setting and update it assigned value, assuming the intended feature controlled by the setting is utilized.

  • cas.ticket.registry.jpa.driver-class=org.hsqldb.jdbcDriver
  • The JDBC driver used to connect to the database.

  • cas.ticket.registry.jpa.password=
  • The database connection password.

  • cas.ticket.registry.jpa.url=jdbc:hsqldb:mem:cas-hsql-database
  • The database connection URL.

  • cas.ticket.registry.jpa.user=sa
  • The database user.

    The database user must have sufficient permissions to be able to handle schema changes and updates, when needed.

    The configuration settings listed below are tagged as Optional in the CAS configuration metadata. This flag indicates that the presence of the setting is not immediately necessary in the end-user CAS configuration, because a default value is assigned or the activation of the feature is not conditionally controlled by the setting value.

  • cas.ticket.registry.jpa.autocommit=false
  • The default auto-commit behavior of connections in the pool. Determined whether queries such as update/insert should be immediately executed without waiting for an underlying transaction.

  • cas.ticket.registry.jpa.batch-size=5
  • A non-zero value enables use of JDBC2 batch updates by Hibernate. e.g. recommended values between 5 and 30.

  • cas.ticket.registry.jpa.data-source-name=
  • Attempts to do a JNDI data source look up for the data source name specified. Will attempt to locate the data source object as is, or will try to return a proxy instance of it, in the event that #dataSourceProxy is used.

  • cas.ticket.registry.jpa.data-source-proxy=false
  • Indicates whether JNDI data sources retrieved should be proxied or returned back verbatim.

  • cas.ticket.registry.jpa.ddl-auto=update
  • Hibernate feature to automatically validate and exports DDL to the schema. By default, creates and drops the schema automatically when a session is starts and ends

  • cas.ticket.registry.jpa.default-catalog=
  • Qualifies unqualified table names with the given catalog in generated SQL.

  • cas.ticket.registry.jpa.default-schema=
  • Qualify unqualified table names with the given schema/tablespace in generated SQL.

  • cas.ticket.registry.jpa.dialect=org.hibernate.dialect.HSQLDialect
  • The database dialect is a configuration setting for platform independent software (JPA, Hibernate, etc) which allows such software to translate its generic SQL statements into vendor specific DDL, DML.

  • cas.ticket.registry.jpa.fail-fast-timeout=1
  • Set the pool initialization failure timeout.

    • Any value greater than zero will be treated as a timeout for pool initialization. The calling thread will be blocked from continuing until a successful connection to the database, or until the timeout is reached. If the timeout is reached, then a PoolInitializationException will be thrown.
    • A value of zero will not prevent the pool from starting in the case that a connection cannot be obtained. However, upon start the pool will attempt to obtain a connection and validate that the connectionTestQuery and connectionInitSql are valid. If those validations fail, an exception will be thrown. If a connection cannot be obtained, the validation is skipped and the the pool will start and continue to try to obtain connections in the background. This can mean that callers to DataSource#getConnection() may encounter exceptions.
    • A value less than zero will not bypass any connection attempt and validation during startup, and therefore the pool will start immediately. The pool will continue to try to obtain connections in the background. This can mean that callers to DataSource#getConnection() may encounter exceptions.
    Note that if this timeout value is greater than or equal to zero (0), and therefore an initial connection validation is performed, this timeout does not override the connectionTimeout or validationTimeout; they will be honored before this timeout is applied. The default value is one millisecond.

  • cas.ticket.registry.jpa.health-query=
  • The SQL query to be executed to test the validity of connections.

  • cas.ticket.registry.jpa.idle-timeout=PT10M
  • Controls the maximum amount of time that a connection is allowed to sit idle in the pool.

  • cas.ticket.registry.jpa.isolate-internal-queries=false
  • This property determines whether data source isolates internal pool queries, such as the connection alive test, in their own transaction.

    Since these are typically read-only queries, it is rarely necessary to encapsulate them in their own transaction. This property only applies if #autocommit is disabled.

  • cas.ticket.registry.jpa.isolation-level-name=ISOLATION_READ_COMMITTED
  • Defines the isolation level for transactions. @see org.springframework.transaction.TransactionDefinition

  • cas.ticket.registry.jpa.jpa-locking-timeout=PT1H
  • Indicates the lock duration when one is about to be acquired by the cleaner.

  • cas.ticket.registry.jpa.leak-threshold=3000
  • Controls the amount of time that a connection can be out of the pool before a message is logged indicating a possible connection leak.

  • cas.ticket.registry.jpa.physical-naming-strategy-class-name=org.apereo.cas.hibernate.CasHibernatePhysicalNamingStrategy
  • Fully-qualified name of the class that can control the physical naming strategy of hibernate.

  • cas.ticket.registry.jpa.propagation-behavior-name=PROPAGATION_REQUIRED
  • Defines the propagation behavior for transactions. @see org.springframework.transaction.TransactionDefinition

  • cas.ticket.registry.jpa.properties=
  • Additional settings provided by Hibernate in form of key-value pairs.

  • cas.ticket.registry.jpa.ticket-lock-type=
  • Ticket locking type. Acceptable values are READ,WRITE,OPTIMISTIC,OPTIMISTIC_FORCE_INCREMENT,PESSIMISTIC_READ, PESSIMISTIC_WRITE,PESSIMISTIC_FORCE_INCREMENT,NONE.


    Control global properties that are relevant to Hibernate, when CAS attempts to employ and utilize database resources, connections and queries.

  • cas.jdbc.case-insensitive=false
  • When choosing physical table names, determine whether names should be considered case-insensitive.

  • cas.jdbc.gen-ddl=true
  • Whether to generate DDL after the EntityManagerFactory has been initialized creating/updating all relevant tables.

  • cas.jdbc.physical-table-names=
  • Indicate a physical table name to be used by the hibernate naming strategy in case table names need to be customized for the specific type of database. The key here indicates the CAS-provided table name and the value is the translate physical name for the database. If a match is not found for the CAS-provided table name, then that name will be used by default.

  • cas.jdbc.show-sql=false
  • Whether SQL queries should be displayed in the console/logs.

    Note that the default value for Hibernate’s DDL setting is create-drop which may not be appropriate for use in production. Setting the value to validate may be more desirable, but any of the following options can be used:

    Type Description
    validate Validate the schema, but make no changes to the database.
    update Update the schema.
    create Create the schema, destroying previous data.
    create-drop Drop the schema at the end of the session.
    none Do nothing.

    Note that during a version migration where any schema has changed create-drop will result in the loss of all data as soon as CAS is started. For transient data like tickets this is probably not an issue, but in cases like the audit table important data could be lost. Using update, while safe for data, is confirmed to result in invalid database state. validate or none settings are likely the only safe options for production use.

    For more information on configuration of transaction levels and propagation behaviors, please review this guide.

    Container-based JDBC Connections

    If you are planning to use a container-managed JDBC connection with CAS (i.e. JPA Ticket/Service Registry, etc) then you can set the data-source-name property on any of the configuration items that require a database connection. When using a container configured data source, many of the pool related parameters will not be used. If data-source-name is specified but the JNDI lookup fails, a data source will be created with the configured (or default) CAS pool parameters.

    If you experience classloading errors while trying to use a container datasource, you can try setting the data-source-proxy setting to true which will wrap the container datasource in a way that may resolve the error.

    The data-source-name property can be either a JNDI name for the datasource or a resource name prefixed with java:/comp/env/. If it is a resource name then you need an entry in a web.xml that you can add to your CAS overlay. It should contain an entry like this:

    1
    2
    3
    4
    5
    
    <resource-ref>
        <res-ref-name>jdbc/casDataSource</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
    

    In Apache Tomcat, a container datasource can be defined like this in the context.xml:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    
    <Resource name="jdbc/casDataSource"
              auth="Container"
              type="javax.sql.DataSource"
              driverClassName="org.postgresql.Driver"
              url="jdbc:postgresql://casdb.example.com:5432/xyz_db"
              username="cas"
              password="xyz"
              testWhileIdle="true"
              testOnBorrow="true"
              testOnReturn="false"
              validationQuery="select 1"
              validationInterval="30000"
              timeBetweenEvictionRunsMillis="30000"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              minIdle="0"
              maxIdle="5"
              initialSize="0"
              maxActive="20"
              maxWait="10000" />
    

    In Jetty, a pool can be put in JNDI with a jetty.xml or jetty-env.xml file like this:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    
    <?xml version="1.0"?>
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
    
    <Configure class="org.eclipse.jetty.webapp.WebAppContext">
        <New id="datasource.cas" class="org.eclipse.jetty.plus.jndi.Resource">
            <Arg></Arg> <!-- empty scope arg is JVM scope -->
            <Arg>jdbc/casDataSource</Arg> <!-- name that matches resource in web.xml-->
            <Arg>
                <New class="org.apache.commons.dbcp.BasicDataSource">
                    <Set name="driverClassName">oracle.jdbc.OracleDriver</Set>
                    <Set name="url">jdbc:oracle:thin:@//casdb.example.com:1521/ntrs"</Set>
                    <Set name="username">cas</Set>
                    <Set name="password">xyz</Set>
                    <Set name="validationQuery">select dummy from dual</Set>
                    <Set name="testOnBorrow">true</Set>
                    <Set name="testOnReturn">false</Set>
                    <Set name="testWhileIdle">false</Set>
                    <Set name="defaultAutoCommit">false</Set>
                    <Set name="initialSize">0</Set>
                    <Set name="maxActive">15</Set>
                    <Set name="minIdle">0</Set>
                    <Set name="maxIdle">5</Set>
                    <Set name="maxWait">2000</Set>
                </New>
            </Arg>
        </New>
    </Configure>
    

    Configuration Metadata

    The collection of configuration properties listed in this section are automatically generated from the CAS source and components that contain the actual field definitions, types, descriptions, modules, etc. This metadata may not always be 100% accurate, or could be lacking details and sufficient explanations. Over time and with community contributions, the accuracy and volume of the documentation should improve over time.

    Be Selective

    This section is meant as a guide only. Do NOT copy/paste the entire collection of settings into your CAS configuration; rather pick only the properties that you need. Do NOT enable settings unless you are certain of their purpose and do NOT copy settings into your configuration only to keep them as reference. All these ideas lead to upgrade headaches, maintenance nightmares and premature aging.

    YAGNI

    Note that for nearly ALL use cases, declaring and configuring properties listed below is sufficient. You should NOT have to explicitly massage a CAS XML/Java/etc configuration file to design an authentication handler, create attribute release policies, etc. CAS at runtime will auto-configure all required changes for you. If you are unsure about the meaning of a given CAS setting, do NOT turn it on without hesitation. Review the codebase or better yet, ask questions to clarify the intended behavior.

    Naming Convention

    Property names can be specified in very relaxed terms. For instance cas.someProperty, cas.some-property, cas.some_property are all valid names. While all forms are accepted by CAS, there are certain components (in CAS and other frameworks used) whose activation at runtime is conditional on a property value, where this property is required to have been specified in CAS configuration using kebab case. This is both true for properties that are owned by CAS as well as those that might be presented to the system via an external library or framework such as Spring Boot, etc. When possible, properties should be stored in lower-case kebab format, such as cas.property-name=value.S ettings and properties that are controlled by the CAS platform directly always begin with the prefix cas. All other settings are controlled and provided to CAS via other underlying frameworks and may have their own schemas and syntax. BE CAREFUL with the distinction. Unrecognized properties are rejected by CAS and/or frameworks upon which CAS depends. This means if you somehow misspell a property definition or fail to adhere to the dot-notation syntax and such, your setting is entirely refused by CAS and likely the feature it controls will never be activated in the way you intend.

    Validation

    Configuration properties are automatically validated on CAS startup to report issues with configuration binding, specially if defined CAS settings cannot be recognized or validated by the configuration schema. The validation process is on by default and can be skipped on startup using a special system property SKIP_CONFIG_VALIDATION that should be set to true. Additional validation processes are also handled via Configuration Metadata and property migrations applied automatically on startup by Spring Boot and family.

    Indexed Settings

    CAS settings able to accept multiple values are typically documented with an index, such as cas.some.setting[0]=value. The index [0] is meant to be incremented by the adopter to allow for distinct multiple configuration blocks.

    Time Unit of Measure

    All CAS settings that deal with time units, unless noted otherwise, should support the duration syntax for full clarity on unit of measure: PT20S, PT15M, PT10H, PT6D, P2DT3H4M.

    A background cleaner process is also automatically scheduled to scan the chosen database periodically and remove expired records based on configured threshold parameters.

    The following settings and properties are available from the CAS configuration catalog:

    The configuration settings listed below are tagged as Required in the CAS configuration metadata. This flag indicates that the presence of the setting is not strictly necessary in the end-user CAS configuration, because a default value may be assigned or the feature in question may not be immediately intended for use. You may want to own the setting and update it assigned value, assuming the intended feature controlled by the setting is utilized.

    The configuration settings listed below are tagged as Optional in the CAS configuration metadata. This flag indicates that the presence of the setting is not immediately necessary in the end-user CAS configuration, because a default value is assigned or the activation of the feature is not conditionally controlled by the setting value.