Limit Spring Beans in Expressions in Spring Boot

Hi,

I’m trying to limit the Spring beans available in expressions. Ive looked at the following

and have managed to get it working in the following way

@Configuration
@AllArgsConstructor
public class SpringBeanConfig {

  private final List<WorkflowService> services;
  private final List<WorkflowDelegate> delegates;

  @Bean
  public SpringProcessEngineConfiguration springProcessEngineConfiguration(List<ProcessEnginePlugin> processEnginePlugins) {
    SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
    CamundaSpringBootUtil.initCustomFields(config);
    config.getProcessEnginePlugins().add(new CompositeProcessEnginePlugin(processEnginePlugins));

    Map<Object, Object> beans = new HashMap<>();
    // add all services that are allowed to be accessed
    beans.putAll(services.stream()
        .collect(Collectors.toMap(service -> ClassUtils.getShortNameAsProperty(service.getClass()), s -> s)));
    // add all delegates that are allowed to be accessed
    beans.putAll(delegates.stream()
        .collect(Collectors.toMap(service -> ClassUtils.getShortNameAsProperty(service.getClass()), s -> s)));
    config.setBeans(beans);
    return config;
  }

}

My question is, is there a better way of doing this? As I’ve tried getting the existing SpringProcessEngineConfiguration and setting the beans on it but the ProcessEngineFactoryBean#initializeExpressionManager has already been called by then.

Thanks,

Matt

1 Like