Is there a way to limit the spring beans that are made available to scripts?
Currently we are able to limit their availability in expressions using the following (where WorkflowBean is a marker interface)
@Configuration
@AllArgsConstructor
public class SpringBeanConfig {
private final List<WorkflowBean> workflowBeans;
@Bean
public SpringProcessEngineConfiguration springProcessEngineConfiguration(List<ProcessEnginePlugin> processEnginePlugins) {
SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
CamundaSpringBootUtil.initCustomFields(config);
config.getProcessEnginePlugins().add(new CompositeProcessEnginePlugin(processEnginePlugins));
config.setBeans(workflowBeans.stream()
.collect(Collectors.toMap(bean -> ClassUtils.getShortNameAsProperty(bean.getClass()), bean -> bean)));
return config;
}
}
But this does seem to affect the availability of the beans within scripts. Any ideas on what can be done would be helpful.
Just incase this helps anyone else, this is how I did it in the end.
Created my own implementation of the SpringProcessEngineConfiguration to remove the SpringBeansResolverFactory and allows other implementation of Resolver factories to be added if needed. But for my purposes I just needed to remove the SpringBeansResolverFactory.
public class CustomSpringProcessEngineConfiguration extends SpringProcessEngineConfiguration {
@Override
protected void initScripting() {
super.initScripting();
// remove SpringBeansResolverFactory
this.getResolverFactories().removeAll(
this.getResolverFactories().stream()
.filter(SpringBeansResolverFactory.class::isInstance)
.collect(Collectors.toList())
);
// could add our own implementation of a spring bean resolver or any other custom resolver
// this.getResolverFactories().add(new SpringBeansResolverFactory(applicationContext));
}
}
And in my SpringBeanConfig component I just needed to use the custom configuration instead as the setting of the Beans still provided the scripting the spring beans I required.
@Configuration
@AllArgsConstructor
public class SpringBeanConfig {
private final List<WorkflowBean> workflowBeans;
@Bean
public SpringProcessEngineConfiguration springProcessEngineConfiguration(List<ProcessEnginePlugin> processEnginePlugins) {
CustomSpringProcessEngineConfiguration config = new CustomSpringProcessEngineConfiguration();
CamundaSpringBootUtil.initCustomFields(config);
config.getProcessEnginePlugins().add(new CompositeProcessEnginePlugin(processEnginePlugins));
config.setBeans(workflowBeans.stream()
.collect(Collectors.toMap(bean -> ClassUtils.getShortNameAsProperty(bean.getClass()), bean -> bean)));
return config;
}
}
Hope thats helps anyone else thats been wondering how to do this.