The Switch action allows the conditional execution of inner actions, based on conditions over the input authentication attributes.
A Switch action is configured with a list of switch cases, where each case is composed by:
true
When the Switch Action is executed, it sequentially evaluates the conditions for each case and calls the action of the first case that evaluates to true. At most one inner action is called, even if there are more than one case with an expression evaluating to true.
A Switch Action instance can be interpreted as a sequence of one if(condition(attributes)) {action(attributes)} followed by zero or more else if(condition(attributes)){action(attributes)}.
if(condition(attributes)) {action(attributes)}
else if(condition(attributes)){action(attributes)}
If no case expression evaluates to true, then one of two things happens:
fail-if-no-match
false
Each switch case can reference any other action, including another Switch action. The only limitation is that a Switch action can not reference itself, directly or indirectly, since that could result in an endless loop. Only direct self-references are checked during configuration, however indirect references are checked during execution.
If a case needs to have more than one action, then a Sequence Action can be used to wrap multiple actions into a single one.
A Switch Action case condition is a JavaScript boolean expression, where the attributes identifier refers to a map containing the following fields:
attributes
subject
context
client
action
The following table presents some examples for these conditions.
attributes.subject.username === 'Alice'
username
attributes.context.location.country === 'Sweden'
location
country
Sweden
attributes.context.riskLevel > 2 && attributes.context.riskLevel < 5
riskLevel
2
5
/.*@example\.com/.test(attributes.subject.email || attributes.subject['e-post'])
email
e-post
example.com
attributes.client.properties.group === 'external'
group
external
attributes.client.id === 'my-good-client'
client_id
my-good-client
attributes.action.someInternalAttribute === 42
someInternalAttribute
42
See Client Object for the available client properties.
Each case list item has the following elements
When using the programmatic configuration interfaces, the condition-script needs to be encoded in Base64. When using the administration graphical interface, this encoding is done automatically.
condition-script
As an example, the following XML excerpt
<authentication-action> <id>switch-1</id> <switch xmlns="https://curity.se/ns/ext-conf/switch"> <case> <name>low-risk</name> <!-- "attributes.context.riskLevel < 2" --> <condition-script>YXR0cmlidXRlcy5jb250ZXh0LnJpc2tMZXZlbCA8IDI=</condition-script> <action>action-0</action> </case> <case> <name>high-risk</name> <!-- "attributes.context.riskLevel >= 2" --> <condition-script>YXR0cmlidXRlcy5jb250ZXh0LnJpc2tMZXZlbCA+PSAy</condition-script> <action>action-1</action> </case> </switch> </authentication-action>
defines the switch-0 sequence action, which when executed:
switch-0
action-0
action-1