Environment
- A Camunda project with version >= 7.12.0 that uses the engine-spring module (including all Spring Boot setups)
Description
- According to https://docs.camunda.org/manual/7.14/user-guide/spring-framework-integration/expressions/#limit-the-exposing-spring-beans-in-expressions, if any custom beans are defined in a process engine configuraiton, no beans should be resolved from the application context
- This documentation talks about JUEL expressions, but the same should apply to scripts to be consistent
Steps to reproduce
- Define a custom bean with name fooBean in the engine configuration (like described in https://docs.camunda.org/manual/7.14/user-guide/spring-framework-integration/expressions/#limit-the-exposing-spring-beans-in-expressions for example)
- Create a bean called fooBean in the Spring application context (i.e. a different object than the one in step 1)
- Create a script task that references fooBean, e.g. with Groovy calling a method fooBean.doSomething()
Observed Behavior
- fooBean resolves to the bean from the application context (step 2)
Expected behavior
- fooBean resolves to the custom bean from the engine configuration (step 1)
Root Cause
- When using a Spring engine configuration, an additional script resolver is added to resolve script variables from the Spring application context, see https://github.com/camunda/camunda-bpm-platform/blob/7.14.0/engine-spring/core/src/main/java/org/camunda/bpm/engine/spring/SpringProcessEngineConfiguration.java#L45-L47
- In super.initScripting(), another resolver for the custom beans is registered
- If two resolvers can resolve an object with the same name, then the last resolver wins; in our case, this means that the application context resolver always wins over the custom beans resolver
Solution Ideas
- The application context resolver is registered only if no custom beans are set
- The behavior should be consistent with the behavior for expressions as defined in https://docs.camunda.org/manual/7.14/user-guide/spring-framework-integration/expressions/#limit-the-exposing-spring-beans-in-expressions, i.e.
- If no custom beans are set, then the application context beans are exposed
- If custom beans are set, no application context beans are exposed
- If an empty map of custom beans is set, then also no application context beans are exposed
Hints
- See https://github.com/camunda/camunda-bpm-platform/blob/7.14.0/engine-spring/core/src/main/java/org/camunda/bpm/engine/spring/SpringExpressionManager.java#L63-L69 for where this is implemented in the case of JUEL expressions
- Note that in ProcessEngineConfigurationImpl#initBeans, the beans map is instantiated if no the user has not supplied anything => we need to distinguish this case from the case that the user has provided an empty map to get all of the cases mentioned under "Solution Ideas" right
This is the controller panel for Smart Panels app
- is related to
-
CAM-10853 Allow Spring Bean methods to be called from Script Tasks
- Closed