j-easy / easy-rules

The simple, stupid rules engine for Java
https://github.com/j-easy/easy-rules/wiki
MIT License
4.86k stars 1.05k forks source link

Would it be possible to set another implementation of `EvaluationContext` (SPEL)? #337

Open pavlo opened 3 years ago

pavlo commented 3 years ago

Hey! First off, thank you a lot for the wonderful tool you've built!

I have a question regarding the fact that it sets StandardEvaluationContext by default, see it SpELCondition.java, line 96. The standard one is way too open as for the project I am working with so the SimpleEvaluationContext would be much safer choice.

As far as I can see there's no way to supply an other kind of EvaluationContext currently (the way it is now possible to supply a bean resolver or parser context) so I wanted to see your thoughts on the matter and maybe a few hints around how it should be done architecturally-speaking... I'll then get it hacked and return you a PR for review.

Thanks a lot! P

fmbenhassine commented 3 years ago

Hi @pavlo , thank you! I'm glad you like easy rules.

The choice of StandardEvaluationContext in preference to SimpleEvaluationContext is because the SimpleEvaluationContext does not fully support SpEL and other features like java type references, bean references, etc. Here is an excerpt from Spring docs:

SimpleEvaluationContext is designed to support only a subset of the SpEL language syntax.
It excludes Java type references, constructors, and bean references. It also requires you to explicitly
choose the level of support for properties and methods in expressions.

I didn't want the default to be limiting to Easy Rules users (ie require an additional config action to enable such features). That said, I remember I tried to make SpEL condition/action work against the EvaluationContext interface but this interface does not contain the setRootObject method which is needed by SpEL condition/action. Do you see?