Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: authorization_services/topics/policy-js-policy.adoc #29085

Open
1 of 2 tasks
shalphaaslam opened this issue Apr 25, 2024 · 2 comments
Open
1 of 2 tasks

Docs: authorization_services/topics/policy-js-policy.adoc #29085

shalphaaslam opened this issue Apr 25, 2024 · 2 comments

Comments

@shalphaaslam
Copy link

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

docs

Describe the bug

File: authorization_services/topics/policy-js-policy.adoc

Version

24.0.3

Regression

  • The issue is a 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

Expected an operand but found const at const context = $evaluation.getContext();
in org.openjdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException

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.

@keycloak-github-bot
Copy link

Due to the amount of issues reported by the community we are not able to prioritise resolving this issue at the moment.

If you are affected by this issue, upvote it by adding a 👍 to the description. We would also welcome a contribution to fix the issue.

@sguilhen
Copy link
Contributor

I think it might be worth adding something to the docs regarding the compatibility of JS features according to the Nashorn version found in the JDK. Adding help-wanted label as the team won't have bandwidth to jump into it, so any contributions from community are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants