Various custom configuration elements support a common content model used to supply JSR-223 scripts inside other object configurations. Where applicable, the specific configuration elements that share this content model will link to this page. These include the following documentation pages:
This feature is new in V3.4 and is a supplement to the older supported approach of defining scripted beans in native Spring files and referring to the beans by reference.
Configuration elements that contain scripts are of type ScriptType
, which is a type used across a number of namespaces. The specific namespace will depend on where the element shows up in your configuration.
The following sections describe the attributes and child elements of an element of type ScriptType
.
AttributesAn element of type
If the Child ElementsAn element of type
The script may be stored in a local file (with
|
Each element of type ScriptType
provides relevant script context, that is, one or more input objects (in the general sense) to be utilized by the script. For specific details, consult the individual configuration element pages listed above.
The following example illustrates the use of a CDATA section
<Script> <![CDATA[ // script goes here ]]> </Script> |
For additional examples of scripts, consult the individual configuration element pages listed above.
The default scripting language is JavaScript (language=”javascript”
). Therefore all of the sample scripts are written in JavaScript, which is based on the ECMAScript standard. The following table illustrates the relationship between JRE version and ECMAScript version:
JRE Version | Default Script Engine | ECMAScript Version |
Java 7 | Rhino | ECMAScript for XML (E4X) |
Java 8 | Nashorn | ECMAScript 5.1 (June 2011) |
Java 9 | Nashorn | ECMAScript 5.1 (plus some features of ECMAScript 2015 aka ECMAScript 6) |
Since Java 7 reached end-of-life on April 2015, we assume Java 8 or above, and therefore the sample scripts aim to conform to ECMAScript 5.1. That said, many of the sample scripts (which are quite simple) will run under both Rhino and Nashorn.
If you’re still using Rhino, the sooner you migrate to Nashorn, the better. Consult the Rhino Migration Guide and this Java 8 Nashorn Tutorial for helpful advice. |
Language features introduced in ECMAScript 2015 (aka ECMAScript 6) are intentionally not used in the sample scripts for compatibility reasons. This includes let , const , and the so-called fat arrow function notation. |
Many of the sample scripts are written in Strict Mode. Such a script will include an explicit “use strict” directive, which intentionally precludes the use of certain (error-prone) JavaScript features. Although Strict Mode was introduced in ECMAScript 5, the “use strict” directive is a harmless addition to any script. In particular, it has no effect (positive or negative) when used in scripts under Rhino. That said, you may disable Strict Mode at any time simply by removing (or commenting out) the “use strict” directive.
Write all your scripts in Strict Mode. Moreover, check all your scripts against JSLint. Both practices will help you write better JavaScript code that is more easily debugged and maintained. |
The JSLint tool does not like the input object and other objects that seem to magically appear from nowhere. From a Shibboleth perspective, this is a feature, not a bug. You can safely ignore this warning issued by the JSLint tool. |