WORKERS AHEAD!
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. You are most encouraged to test the changes presented.
Service Template Definitions
A registered service template definition is the foundation and initial building block to construct a service definition. Acting as a blueprint, a template definition will specify a framework for what a given registered service definition might look like. For example, a service template definition might want to specify a collection common settings and application policies for a given service type, such as attribute release and consent policies, to remove the need for those policies to be specified yet again in future service definitions that might stem from that blueprint. Concrete service definitions will automatically inherit from future improvements/changes to the template.
A few important considerations:
- Concrete service definitions always have the ability to override the template definition and enforce their own policy and settings to allow for exceptions. Their version of the configuration and policy will always override the base template. The merging process is not exactly fine-tuned to pick out individual differences in configuration blocks.
- Concrete service definitions may link up with a template definition using their template name and type. This design choice allows the CAS deployer to define multiple service definition blueprints and templates for the same type of CAS applications with different names.
- Service definitions are not required to build and spin off of a blueprint and can remain and function in a standalone manner.
- The relationship and inheritance hierarchy between a template definition and concrete definitions is fixed at one level or degree and is not recursive. However, composition is favored over inheritance and you may assign multiple template definition names to a concrete service in a comma-separated fashion.
Template service definitions work for and apply to all types of registered service definitions known to CAS and are not restricted to a specific type or protocol. The resulting service definition after the merge operation is always internal to CAS, and is not something you can manage and/or maintain separately.
The directory location of template service definitions needs to be taught to CAS via settings. This directory is
expected to hold .json
service definition files that structurally are no different than any given registered service in CAS.
The directory is searched for template definitions recursively, and you may come up with your own directory structure to group
definitions by type, application, etc.
Remember that a service template definition filename MUST match the template name itself. The formula for naming template definition files should be:
1
templateFileName = templateName + ".json"
Configuration
The following settings and properties are available from the CAS configuration catalog:
cas.service-registry.templates.directory.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 . In situations and scenarios where CAS is able to automatically watch the underlying resource for changes and detect updates and modifications dynamically, you may be able to specify the following setting as either an environment variable or system property with a value of false to disable the resource watcher: org.apereo.cas.util.io.PathWatcherService .
|
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.
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 here 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
.
The only possible exception to this rule is when naming actuator endpoints; The name of the
actuator endpoints (i.e. ssoSessions
) MUST remain in camelCase mode.
Settings 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. 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.
Please note that processing template service definitions requires scripting. To prepare CAS to support and integrate with Apache Groovy, please review this guide.
Examples
Consider the following base template service definition, stored in a AllLibraryApplications.json
file,
for a yet-to-be-registered CAS application:
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
28
29
{
"@class": "org.apereo.cas.services.CasRegisteredService",
"templateName": "AllLibraryApplications",
"attributeReleasePolicy" : {
"@class" : "org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy",
"allowedAttributes" : [ "java.util.ArrayList", [ "email", "username" ] ],
"consentPolicy": {
"@class": "org.apereo.cas.services.consent.DefaultRegisteredServiceConsentPolicy",
"includeOnlyAttributes": ["java.util.LinkedHashSet", ["email", "username"]],
"status": "TRUE"
}
},
"usernameAttributeProvider" : {
"@class" : "org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider",
"usernameAttribute" : "email",
"canonicalizationMode" : "LOWER"
},
"properties" : {
"@class" : "java.util.HashMap",
"prop1": {
"@class" : "org.apereo.cas.services.DefaultRegisteredServiceProperty",
"values" : [ "java.util.HashSet", [ "false" ] ]
},
"prop2" : {
"@class" : "org.apereo.cas.services.DefaultRegisteredServiceProperty",
"values" : [ "java.util.HashSet", [ "hello-world" ] ]
}
}
}
The following variations are possible:
-
A concrete service definition may link up with a template:
1 2 3 4 5 6 7 8 9 10 11 12
{ "@class": "org.apereo.cas.services.CasRegisteredService", "serviceId": "^https://library.org/app/.+", "name": "Library", "templateName": "AllLibraryApplications", "id": 1, "description": "My application", "usernameAttributeProvider" : { "@class" : "org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider", "usernameAttribute" : "givenName", } }
The final result, when processed and loaded internally by CAS would be the following definition:
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 28 29 30 31 32
{ "@class": "org.apereo.cas.services.CasRegisteredService", "name": "Library", "templateName": "AllLibraryApplications", "serviceId": "^https://library.org/app/.+", "id": 1, "description": "My application", "attributeReleasePolicy" : { "@class" : "org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy", "allowedAttributes" : [ "java.util.ArrayList", [ "email", "username" ] ], "consentPolicy": { "@class": "org.apereo.cas.services.consent.DefaultRegisteredServiceConsentPolicy", "includeOnlyAttributes": ["java.util.LinkedHashSet", ["email", "username"]], "status": "TRUE" } }, "usernameAttributeProvider" : { "@class" : "org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider", "usernameAttribute" : "givenName", }, "properties" : { "@class" : "java.util.HashMap", "prop1": { "@class" : "org.apereo.cas.services.DefaultRegisteredServiceProperty", "values" : [ "java.util.HashSet", [ "false" ] ] }, "prop2" : { "@class" : "org.apereo.cas.services.DefaultRegisteredServiceProperty", "values" : [ "java.util.HashSet", [ "hello-world" ] ] } } }
-
A concrete service definition may link up with a template:
1 2 3 4 5 6 7 8
{ "@class": "org.apereo.cas.services.CasRegisteredService", "serviceId": "^https://library.org/app/.+", "name": "Library", "templateName": "AllLibraryApplications", "id": 1, "description": "My application" }
The final result, when processed and loaded internally by CAS would be the following definition:
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 28 29 30 31 32 33
{ "@class": "org.apereo.cas.services.CasRegisteredService", "name": "Library", "templateName": "AllLibraryApplications", "serviceId": "^https://library.org/app/.+", "id": 1, "description": "My application", "attributeReleasePolicy" : { "@class" : "org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy", "allowedAttributes" : [ "java.util.ArrayList", [ "email", "username" ] ], "consentPolicy": { "@class": "org.apereo.cas.services.consent.DefaultRegisteredServiceConsentPolicy", "includeOnlyAttributes": ["java.util.LinkedHashSet", ["email", "username"]], "status": "TRUE" } }, "usernameAttributeProvider" : { "@class" : "org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider", "usernameAttribute" : "email", "canonicalizationMode" : "LOWER" }, "properties" : { "@class" : "java.util.HashMap", "prop1": { "@class" : "org.apereo.cas.services.DefaultRegisteredServiceProperty", "values" : [ "java.util.HashSet", [ "false" ] ] }, "prop2" : { "@class" : "org.apereo.cas.services.DefaultRegisteredServiceProperty", "values" : [ "java.util.HashSet", [ "hello-world" ] ] } } }
-
A concrete service definition may also specify multiple template names:
1 2 3 4 5 6 7 8 9 10 11 12
{ "@class": "org.apereo.cas.services.CasRegisteredService", "serviceId": "^https://library.org/app/.+", "name": "Library", "templateName": "AllLibraryApplications,UnknownTemplate,AllGenericApplications", "id": 1, "description": "My application", "usernameAttributeProvider" : { "@class" : "org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider", "usernameAttribute" : "givenName", } }
Template definitions will be applied in the same order as they are defined. Assuming both
AllLibraryApplications
andAllGenericApplications
template definition files exist and have been loaded by CAS, the merge process will go through each assigned template sequentially, carrying the results of previous merge attempts and will also ignore unknown templates that cannot be found and resolved. -
Service template definitions can be as designed Groovy templates, able to generate text and other constructs dynamically. The template framework in Groovy uses JSP style
<% %>
script and<%= %>
expression syntax orGString
style expressions. The variableout
is bound to the writer that the template is being written to.To prepare CAS to support and integrate with Apache Groovy, please review this guide.
For example consider the following
GroovyTemplate
template definition:1 2 3 4 5 6 7 8 9 10 11 12 13 14
{ "@class": "org.apereo.cas.services.CasRegisteredService", "name": "CAS", "description": "${GivenDescription}", "templateName": "GroovyTemplate", "usernameAttributeProvider" : { "@class" : "org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider", "usernameAttribute" : "${GivenUsernameAttribute}" }, "attributeReleasePolicy" : { "@class" : "org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy", "allowedAttributes" : [ "java.util.ArrayList", ${ AllowedAttributes.collect(it -> "\"$it\"") } ] } }
The
description
,usernameAttribute
andallowedAttributes
fields will be dynamically constructed at the time of building a concrete service definition. The values for each of these fields is expected to be found from variablesGivenDescription
,GivenUsernameAttribute
, andAllowedAttributes
that are to be supplied by the concrete service definition in the form of service properties:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
{ "@class": "org.apereo.cas.services.CasRegisteredService", "serviceId": "^https://library.org/app/.+", "name": "Library", "templateName": "GroovyTemplate", "id": 1000, "properties": { "@class": "java.util.HashMap", "GivenDescription": { "@class": "org.apereo.cas.services.DefaultRegisteredServiceProperty", "values": [ "java.util.LinkedHashSet", [ "This is my description" ] ] }, "AllowedAttributes": { "@class": "org.apereo.cas.services.DefaultRegisteredServiceProperty", "values": [ "java.util.LinkedHashSet", [ "email", "username" ] ] }, "GivenUsernameAttribute": { "@class": "org.apereo.cas.services.DefaultRegisteredServiceProperty", "values": [ "java.util.LinkedHashSet", [ "email" ] ] } } }
After the merge process is completed, the final result would be similar to the following definition:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
{ "@class": "org.apereo.cas.services.CasRegisteredService", "name": "CAS", "templateName": "GroovyTemplate", "id": 1000, "description": "This is my description", "usernameAttributeProvider": { "@class": "org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider", "usernameAttribute": "email" }, "attributeReleasePolicy": { "@class": "org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy", "allowedAttributes": [ "java.util.ArrayList", [ "email", "username" ] ] } }