Database Authentication

Database authentication is enabled by including the following dependencies in the WAR overlay:

implementation "org.apereo.cas:cas-server-support-jdbc:${project.'cas.version'}"
<dependency>
  <groupId>org.apereo.cas</groupId>
  <artifactId>cas-server-support-jdbc</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-jdbc"
}

To learn how to configure database drivers, please see this guide.

Configuration

Query Database Authentication

Authenticates a user by comparing the user password (which can be encoded with a password encoder) against the password on record determined by a configurable database query.

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.authn.jdbc.query[0].password-encoder.encoding-algorithm=
  • The encoding algorithm to use such as 'MD5'. Relevant when the type used is 'DEFAULT' or 'GLIBC_CRYPT'.

  • cas.authn.jdbc.query[0].password-encoder.type=NONE
  • Define the password encoder type to use. Type may be specified as blank or 'NONE' to disable password encoding. It may also refer to a fully-qualified class name that implements the Spring Security's PasswordEncoder interface if you wish you define your own encoder. The following types may be used:

    • NONE: No password encoding (i.e. plain-text) takes place.
    • DEFAULT: Use the DefaultPasswordEncoder of CAS. For message-digest algorithms via #getCharacterEncoding() and #getCharacterEncoding().
    • BCRYPT: Use the BCryptPasswordEncoder based on the strength provided and an optional secret.
    • SCRYPT: Use the SCryptPasswordEncoder.
    • PBKDF2: Use the Pbkdf2PasswordEncoder based on the strength provided and an optional secret.
    • STANDARD: Use the StandardPasswordEncoder based on the secret provided.
    • SSHA: Use the LdapShaPasswordEncoder supports Ldap SHA and SSHA (salted-SHA). The values are base-64 encoded and have the label SHA</code> (or SSHA</code>) prepended to the encoded hash.
    • GLIBC_CRYPT: Use the GlibcCryptPasswordEncoder based on the encoding-algorithm, strength provided and an optional secret.
    • org.example.MyEncoder: An implementation of PasswordEncoder of your own choosing.
    • file:///path/to/script.groovy: Path to a Groovy script charged with handling password encoding operations.

  • cas.authn.jdbc.query[0].principal-transformation.groovy.location=
  • The location of the resource. Resources can be URLS, or files found either on the classpath or outside somewhere in the file system.

  • cas.authn.jdbc.query[0].driver-class=org.hsqldb.jdbcDriver
  • The JDBC driver used to connect to the database.

  • cas.authn.jdbc.query[0].field-password=
  • Password field/column name to retrieve.

  • cas.authn.jdbc.query[0].password=
  • The database connection password.

  • cas.authn.jdbc.query[0].sql=
  • SQL query to execute. Example: SELECT * FROM table WHERE name=?.

  • cas.authn.jdbc.query[0].url=jdbc:hsqldb:mem:cas-hsql-database
  • The database connection URL.

  • cas.authn.jdbc.query[0].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.authn.jdbc.query[0].password-encoder.character-encoding=UTF-8
  • The encoding algorithm to use such as 'UTF-8'. Relevant when the type used is 'DEFAULT'.

  • cas.authn.jdbc.query[0].password-encoder.secret=
  • Secret to use with STANDARD, PBKDF2, BCRYPT, GLIBC_CRYPT password encoders. Secret usually is an optional setting.

  • cas.authn.jdbc.query[0].password-encoder.strength=16
  • Strength or number of iterations to use for password hashing. Usually relevant when dealing with PBKDF2 or BCRYPT encoders. Used by GLIBC_CRYPT encoders as well.

  • cas.authn.jdbc.query[0].principal-transformation.blocking-pattern=
  • A regular expression that will be used against the username to match for blocking/forbidden values. If a match is found, an exception will be thrown and principal transformation will fail.

  • cas.authn.jdbc.query[0].principal-transformation.case-conversion=
  • Indicate whether the principal identifier should be transformed into upper-case, lower-case, etc. Available values: NONE:No conversion. LOWERCASE:Lowercase conversion. UPPERCASE:Uppercase conversion.

  • cas.authn.jdbc.query[0].principal-transformation.pattern=
  • A regular expression that will be used against the provided username for username extractions. On a successful match, the first matched group in the pattern will be used as the extracted username.

  • cas.authn.jdbc.query[0].principal-transformation.prefix=
  • Prefix to add to the principal id prior to authentication.

  • cas.authn.jdbc.query[0].principal-transformation.suffix=
  • Suffix to add to the principal id prior to authentication.

  • cas.authn.jdbc.query[0].pool.max-size=18
  • Controls the maximum number of connections to keep in the pool, including both idle and in-use connections.

  • cas.authn.jdbc.query[0].pool.max-wait=PT2S
  • Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.

    A value of zero specifies that the timeout is the default system timeout if there is one; otherwise, it specifies that there is no timeout.

  • cas.authn.jdbc.query[0].pool.min-size=6
  • Controls the minimum size that the pool is allowed to reach, including both idle and in-use connections.

  • cas.authn.jdbc.query[0].pool.suspension=
  • Whether or not pool suspension is allowed.

    There is a performance impact when pool suspension is enabled. Unless you need it (for a redundancy system for example) do not enable it.

  • cas.authn.jdbc.query[0].pool.timeout-millis=1_000
  • The maximum number of milliseconds that the pool will wait for a connection to be validated as alive.