AssignmentFilter — conditionally assign values to expressions
{
"name": string,
"type": "AssignmentFilter",
"config": {
"onRequest": [
{
"condition": expression,
"target": lvalue-expression,
"value": expression
}, ...
],
"onResponse": [
{
"condition": expression,
"target": lvalue-expression,
"value": expression
}, ...
]
}
}"onRequest": array of objects,
optionalDefines a list of assignment bindings to evaluate before the exchange is handled.
"onResponse": array of objects,
optionalDefines a list of assignment bindings to evaluate after the exchange is handled.
"condition": expression,
optionalExpression to evaluate to determine if an assignment should occur. Omitting the condition makes the assignment unconditional.
"target": lvalue-expression,
requiredExpression that yields the target object whose value is to be set.
"value": expression,
optionalExpression that yields the value to be set in the target.
This is an example of how you would capture credentials and store them in the Gateway session during a login request. Notice the credentials are captured on the request, but not marked as valid until the response returns a positive 302. The credentials would then be used to login a user to a different application.
{
"name": "PortalLoginCaptureFilter",
"type": "AssignmentFilter",
"config": {
"onRequest": [
{
"target": "${exchange.session.authUsername}",
"value": "${exchange.request.form['username'][0]}",
},
{
"target": "${exchange.session.authPassword}",
"value": "${exchange.request.form['password'][0]}",
},
{
"comment": "Indicates authentication has not yet been confirmed.",
"target": "${exchange.session.authConfirmed}",
"value": "${false}",
}
],
"onResponse": [
{
"condition": "${exchange.response.status == 302}",
"target": "${exchange.session.authConfirmed}",
"value": "${true}",
}
]
}
}