Ticket-Granting Ticket REST Protocol
Ticket-granting tickets can be issued by the REST protocol:
1
2
3
POST /cas/v1/tickets HTTP/1.0
'Content-type': 'Application/x-www-form-urlencoded'
username=battags&password=password&additionalParam1=paramvalue
You may also specify a service
parameter to verify whether the
authenticated user may be allowed to access the given service.
Successful Response
1
2
201 Created
Location: http://www.whatever.com/cas/v1/tickets/{TGT id}
Remember that REST is stateless. Since the caller is the recipient of the ticket-granting ticket that represents a single sign-on session, that means the caller is also responsible for managing and creating single sign-on sessions, removing that responsibility from CAS. In other words, the REST protocol allows one to use CAS as an authentication engine, and not a single sign-on provider. There have been many workarounds, modifications and hacks over the years to bypass this barrier and have REST calls to also, somehow, create the necessary cookies, flows and interactions and whatever else necessary to allow applications to leverage a single sign-on session established via REST. Needless to say, all such endeavors over time have resulted in maintenance headaches, premature aging and loss of DNA.
Unsuccessful Response
If incorrect credentials are sent, CAS will respond with a 401 Unauthorized
. A 400 Bad Request
error
will be sent for missing parameters, etc. If you send a media type it does not
understand, it will send the 415 Unsupported Media Type
.
JWT Ticket Granting Tickets
Ticket-granting tickets created by the REST protocol may be issued as JWTs instead. Support is enabled by including the following in your overlay:
1
2
3
4
5
<dependency>
<groupId>org.apereo.cas</groupId>
<artifactId>cas-server-support-rest-tokens</artifactId>
<version>${cas.version}</version>
</dependency>
1
implementation "org.apereo.cas:cas-server-support-rest-tokens:${project.'cas.version'}"
1
2
3
4
5
6
7
8
9
dependencyManagement {
imports {
mavenBom "org.apereo.cas:cas-server-support-bom:${project.'cas.version'}"
}
}
dependencies {
implementation "org.apereo.cas:cas-server-support-rest-tokens"
}
1
2
3
4
5
6
7
8
9
10
dependencies {
/*
The following platform references should be included automatically and are listed here for reference only.
implementation enforcedPlatform("org.apereo.cas:cas-server-support-bom:${project.'cas.version'}")
implementation platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
*/
implementation "org.apereo.cas:cas-server-support-rest-tokens"
}
To request a ticket-granting ticket as JWT next, ensure the POST
request matches the following:
1
2
3
POST /cas/v1/tickets HTTP/1.0
username=battags&password=password&token=true&additionalParam1=paramvalue
The token
parameter may either be passed as a request parameter or a request
header. The body of the response will include the ticket-granting ticket as
a JWT. Note that JWTs created are typically signed and encrypted by default with pre-generated keys.
The following settings and properties are available from the CAS configuration catalog:
cas.authn.token.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. In the event the configured resource is a Groovy script, specially if the script set to reload on changes, you may need to adjust the total number ofinotify instances. On Linux, you may need to add the following line to /etc/sysctl.conf : fs.inotify.max_user_instances = 256 . You can check the current value via cat /proc/sys/fs/inotify/max_user_instances .
|
cas.authn.token.crypto.encryption.key=
The encryption key is a JWT whose length is defined by the encryption key size setting.
|
cas.authn.token.crypto.signing.key=
The signing key is a JWT whose length is defined by the signing key size setting.
|
cas.authn.token.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.token.principal-transformation.case-conversion=NONE
Indicate whether the principal identifier should be transformed into upper-case, lower-case, etc. Available values are as follows:
|
cas.authn.token.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.token.principal-transformation.prefix=
Prefix to add to the principal id prior to authentication.
|
cas.authn.token.principal-transformation.suffix=
Suffix to add to the principal id prior to authentication.
|
cas.authn.token.crypto.alg=
The signing/encryption algorithm to use.
|
cas.authn.token.crypto.enabled=true
Whether crypto operations are enabled.
|
cas.authn.token.crypto.encryption-enabled=true
Whether crypto encryption operations are enabled.
|
cas.authn.token.crypto.encryption.key-size=512
The encryption key size.
|
cas.authn.token.crypto.signing-enabled=true
Whether crypto signing operations are enabled.
|
cas.authn.token.crypto.signing.key-size=512
The signing key size.
|
cas.authn.token.crypto.strategy-type=ENCRYPT_AND_SIGN
Control the cipher sequence of operations. The accepted values are:
|
cas.authn.token.webflow.enabled=true
Whether webflow auto-configuration should be enabled.
|
cas.authn.token.webflow.order=0
The order in which the webflow is configured.
|