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.
Namespace and Schema
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 An element of type Name Type Default Description If the An element of type The script may be stored in a local file (with Always wrap inline scripts with a CDATA section Always wrap inline scripts with a CDATA section, even if the script contains no special XML characters. This will future-proof your script.
ScriptType has the following XML attributes:
Defines the JSR-223 language to use. The default is ECMAScript using either the Rhino (Java 7) or Nashorn (Java 8) engines.
string optional The ID of a Spring bean defined elsewhere in the configuration.
customObjectRef attribute is present, the result of the referenced Spring bean is made available to the script in a variable named
custom. This is in addition to the normal script context discussed below.
ScriptType has the following child elements:
Name Cardinality Description
An inline script
Path to a local file or classpath resource containing the script
<ScriptFile>) or written inline (with
<Script>). An inline script should be wrapped with a CDATA section to prevent interpretation of any special XML characters that may be included in the script.
An element of type
An element of type
The script may be stored in a local file (with
Always wrap inline scripts with a CDATA section
Always wrap inline scripts with a CDATA section, even if the script contains no special XML characters. This will future-proof your script.
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
For additional examples of scripts, consult the individual configuration element pages listed above.
Default Script Engine
ECMAScript for XML (E4X)
ECMAScript 5.1 (June 2011)
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, which implements Nashorn.
Nashorn documentation from Oracle
An introduction to Nashorn from Oracle:
If you’re still using Rhino, the sooner you migrate to Nashorn, the better. That said, many of the sample scripts (which are quite simple) will run under both Rhino and Nashorn.
Still using Rhino?
Since Nashorn is included with Java 8 (and later), the sample scripts aim to conform to ECMAScript 5.1. In particular, the scripts avoid features introduced in ECMAScript 6 (also known as ECMAScript 2015) for compatibility.
ECMAScript 2015 is not supported
const, and the so-called fat arrow function notation.
Follow best coding practices
Using the JSLint tool
- JSLint does not like the
customobjects 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.
Equally it does not like the "last value is the implied return" paradigm. Should this grate you can fool JSLint by using a closure as the last line, for instance replacing
Only you can decide whether this will help maintainabilty. For clarity and didactic purpose the examples omit this paradigm.