Docs: authorization_services/topics/policy-js-policy.adoc #29085
Labels
area/authorization-services
Indicates an issue on Authorization area
area/docs
help wanted
kind/bug
Categorizes a PR related to a bug
priority/normal
status/auto-bump
status/auto-expire
team/core-iam
Before reporting an issue
Area
docs
Describe the bug
File: authorization_services/topics/policy-js-policy.adoc
Version
24.0.3
Regression
Expected behavior
const context = $evaluation.getContext(); is the document example which should work without error
Actual behavior
causes error Expected an operand but found const at const context = $evaluation.getContext();
in org.openjdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException.
Using, var context = $evaluation.getContext(); resolves error
How to Reproduce?
Using the example javascript policy Is enough to reproduce the error below
Anything else?
Hi, I had issue while using this example in my keycloak custom javascript policy. I am using 24.0.2 version. It worked after I change const to var. Keycloak uses the Nashorn JavaScript engine provided by the JDK for executing JavaScript code. The Nashorn engine, as included in OpenJDK 11, supports ECMAScript 5.1 by default, which does not include the const keyword as part of its standard
[The const keyword is a feature of ECMAScript 6 (ES6), and while Nashorn has received some updates to support ES6 features, these may not be enabled by default or fully supported in the version of Nashorn included with OpenJDK 11]. This is why maybe replacing const with var, which is part of ECMAScript 5.1, resolves the issue.
To use ES6 features like const, you might need to enable ES6 mode in Nashorn. This can typically be done by passing the --language=es6 option to the Nashorn engine. However, this might not be directly applicable or available in the context of Keycloak’s script execution environment.
Reporting this issue to update the documentation to reflect the compatibility of JavaScript features with the version of Nashorn included in the JDK that Keycloak is using. Additionally, can help to provide guidance on how to enable ES6 features or work around this limitation.
The text was updated successfully, but these errors were encountered: