From 6b718b66a3bb978dce7a4f50a85425352161ad38 Mon Sep 17 00:00:00 2001 From: Bernd Ruecker Date: Wed, 23 Nov 2022 12:16:17 +0100 Subject: [PATCH] Prepare JobHandler to get SecurityProvider injected (#276) --- .../util/outbound/ConnectorJobHandler.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/runtime-util/src/main/java/io/camunda/connector/runtime/util/outbound/ConnectorJobHandler.java b/runtime-util/src/main/java/io/camunda/connector/runtime/util/outbound/ConnectorJobHandler.java index 82430c2195..986652832e 100644 --- a/runtime-util/src/main/java/io/camunda/connector/runtime/util/outbound/ConnectorJobHandler.java +++ b/runtime-util/src/main/java/io/camunda/connector/runtime/util/outbound/ConnectorJobHandler.java @@ -38,6 +38,7 @@ public class ConnectorJobHandler implements JobHandler { private static final Logger LOGGER = LoggerFactory.getLogger(ConnectorJobHandler.class); protected final OutboundConnectorFunction call; + protected SecretProvider secretProvider; /** * Create a handler wrapper for the specified connector function. @@ -48,6 +49,12 @@ public ConnectorJobHandler(final OutboundConnectorFunction call) { this.call = call; } + public ConnectorJobHandler( + final OutboundConnectorFunction call, final SecretProvider secretProvider) { + this.call = call; + this.secretProvider = secretProvider; + } + @Override public void handle(final JobClient client, final ActivatedJob job) { @@ -89,6 +96,15 @@ public void handle(final JobClient client, final ActivatedJob job) { } protected SecretProvider getSecretProvider() { + if (secretProvider != null) { + return secretProvider; + } + // Initialize in legacy scenario where this is not provided by the environment with every call + // to not break former behavior + return loadOrCreateSecretProvider(); + } + + protected SecretProvider loadOrCreateSecretProvider() { Iterator secretProviders = ServiceLoader.load(SecretProvider.class).iterator(); if (!secretProviders.hasNext()) { getEnvSecretProvider();