Thank you Jon and Laurent for sharing few examples and inputs. I've created a sample mapping rule called testotp and a file called testotp.json shown as below.
TestOTP - InfoMap
---------------
importPackage(Packages.com.tivoli.am.fim.trustserver.sts.utilities);
importClass(Packages.com.tivoli.am.fim.trustserver.sts.utilities.IDMappingExtUtils);
var test = "testjson"
macros.put("@VALUE@", test);
page.setValue("/authsvc/authenticator/testotp/testotp.json");IDMappingExtUtils.traceString("JSON Value" + json);
success.setValue(false);
testotp.json
----------------
{
"status": "@STATUS@",
"mechanism": "@MECHANISM_ID@",
"stateId": "@STATE@",
"location": "@ACTION@",
"value": "@VALUE@"
}
When I use the page.setValue to render the testotp.json file, it's not working. I had to change it to testotp.html to get it working. I am not sure why am not able to load the .json file but the .html is working. Please let me know if this is the expected behavior in AAC module.
Thanks
Vamsi
------------------------------
Vishnu Vamsi
------------------------------
Original Message:
Sent: Tue November 17, 2020 03:30 AM
From: Jon Harry
Subject: Dynamic JSON response to a json template file
Vamsi,
Further to @Laurent LA Asselborn 's answer, here's a useful thing to add to your template page to allow you to see all the macros that are available:
<% java.lang.System.err.println(JSON.stringify(templateContext.macros).replace(/@/g,"")); %>
This script will return a JSON object containing all defined macros in JSON format. The removal of @ characters is needed to stop macro substitution. This will be logged to messages and trace.log.
Not exactly what you're looking for but here's an example login.json file that can return alternative JSON response for the password login mechanism in AAC:
<% templateContext.response.setStatus(401); var errorMsg = templateContext.macros["@ERROR_MESSAGE@"]; if (errorMsg == "") { output = "\"message\" : \"Provide username and password\""; } else { output = "\"error_message\" : \"" + errorMsg + "\""; }%>{ <%=output%>, "location" : "@ACTION@", "mechanism" : "@MECHANISM_ID@"}
Jon.
------------------------------
Jon Harry
Consulting IT Security Specialist
IBM
------------------------------