This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new fb685fa6c201 CAMEL-27732: camel-azure-key-vault - an autowired
SecretClient is used, and the configuration can be set on the component (#31049)
fb685fa6c201 is described below
commit fb685fa6c20102de8c719c1eb7a4874bdae3177e
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Nov 27 22:15:40 2026 +0100
CAMEL-27732: camel-azure-key-vault - an autowired SecretClient is used, and
the configuration can be set on the component (#31049)
The credential check ran in KeyVaultComponent.createEndpoint(), before the
endpoint autowires a single SecretClient of the registry in doInit(). So a
SecretClient bean was not used unless the route also set
credentialType=AZURE_IDENTITY or all three credentials. The check now runs
in
KeyVaultEndpoint.doInit(), after the autowiring.
KeyVaultComponent had a configuration field without a getter and setter, so
the component had no options. It now has getConfiguration() and
setConfiguration(), and clientId, clientSecret, tenantId, credentialType,
operation and secretClient (autowired) are component options too, such as
camel.component.azure-key-vault.client-id.
The doc page explains both, and the early-resolve-properties example no
longer says =true=true.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../camel/catalog/components/azure-key-vault.json | 13 +-
.../catalog/docs/azure-key-vault-component.adoc | 12 +-
.../key/vault/KeyVaultComponentConfigurer.java | 48 +++++++
.../key/vault/KeyVaultEndpointUriFactory.java | 3 +-
.../component/azure/key/vault/azure-key-vault.json | 13 +-
.../src/main/docs/azure-key-vault-component.adoc | 12 +-
.../azure/key/vault/KeyVaultComponent.java | 20 +--
.../azure/key/vault/KeyVaultConfiguration.java | 2 +-
.../azure/key/vault/KeyVaultEndpoint.java | 9 ++
.../azure/key/vault/KeyVaultConfigurationTest.java | 47 ++++++-
.../dsl/AzureKeyVaultComponentBuilderFactory.java | 147 +++++++++++++++++++++
11 files changed, 300 insertions(+), 26 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/azure-key-vault.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/azure-key-vault.json
index 23d51a65d928..6d2fd5019193 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/azure-key-vault.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/azure-key-vault.json
@@ -25,8 +25,15 @@
"remote": true
},
"componentProperties": {
- "lazyStartProducer": { "index": 0, "kind": "property", "displayName":
"Lazy Start Producer", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the producer should be started lazy (on the first message). By
starting lazy you can use this to allow CamelContext and routes to startup in
situations where a producer may otherwise fail [...]
- "autowiredEnabled": { "index": 1, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Whether autowiring is enabled. This is used for automatic autowiring options
(the option must be marked as autowired) by looking up in the registry to find
if there is a single instance of matching t [...]
+ "configuration": { "index": 0, "kind": "property", "displayName":
"Configuration", "group": "producer", "label": "", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"deprecated": false, "autowired": false, "secret": false, "description": "The
configuration that each endpoint of the component starts from, as a copy. The
options of the endpoint replace its values." },
+ "credentialType": { "index": 1, "kind": "property", "displayName":
"Credential Type", "group": "common", "label": "common", "required": false,
"type": "enum", "javaType":
"org.apache.camel.component.azure.common.CredentialType", "enum": [
"CLIENT_SECRET", "AZURE_IDENTITY" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "CLIENT_SECRET", "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configur [...]
+ "lazyStartProducer": { "index": 2, "kind": "property", "displayName":
"Lazy Start Producer", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the producer should be started lazy (on the first message). By
starting lazy you can use this to allow CamelContext and routes to startup in
situations where a producer may otherwise fail [...]
+ "operation": { "index": 3, "kind": "property", "displayName": "Operation",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "org.apache.camel.component.azure.key.vault.KeyVaultOperation",
"enum": [ "createSecret", "getSecret", "updateSecretProperties",
"deleteSecret", "purgeDeletedSecret" ], "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "createSecret", "configurationClass":
"org.apache.camel.component.azure.key.vault [...]
+ "secretClient": { "index": 4, "kind": "property", "displayName": "Secret
Client", "group": "producer", "label": "", "required": false, "type": "object",
"javaType": "com.azure.security.keyvault.secrets.SecretClient", "deprecated":
false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "To use a custom
com.azure.security.keyvault.secrets.SecretClient. Whe [...]
+ "autowiredEnabled": { "index": 5, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Whether autowiring is enabled. This is used for automatic autowiring options
(the option must be marked as autowired) by looking up in the registry to find
if there is a single instance of matching t [...]
+ "clientId": { "index": 6, "kind": "property", "displayName": "Client Id",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The client ID
(application ID) of the Microsoft Entra application for the CLIEN [...]
+ "clientSecret": { "index": 7, "kind": "property", "displayName": "Client
Secret", "group": "security", "label": "security", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The client secret of the
Microsoft Entra application for the CLIENT_SEC [...]
+ "tenantId": { "index": 8, "kind": "property", "displayName": "Tenant Id",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The ID of the Microsoft
Entra tenant (directory) of the application for the CLIENT_SECRET credential
[...]
},
"headers": {
"CamelAzureKeyVaultProducerOperation": { "index": 0, "kind": "header",
"displayName": "", "group": "producer", "label": "producer", "required": false,
"javaType": "org.apache.camel.component.azure.key.vault.KeyVaultOperation",
"enum": [ "createSecret", "getSecret", "updateSecretProperties",
"deleteSecret", "purgeDeletedSecret" ], "deprecated": false, "autowired":
false, "secret": false, "description": "The operation that the producer
performs. It replaces the operation option.", "con [...]
@@ -45,6 +52,6 @@
"lazyStartProducer": { "index": 4, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produc [...]
"clientId": { "index": 5, "kind": "parameter", "displayName": "Client Id",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The client ID
(application ID) of the Microsoft Entra application for the CLIE [...]
"clientSecret": { "index": 6, "kind": "parameter", "displayName": "Client
Secret", "group": "security", "label": "security", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The client secret of the
Microsoft Entra application for the CLIENT_SE [...]
- "tenantId": { "index": 7, "kind": "parameter", "displayName": "Tenant Id",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The ID of the Microsoft
Entra tenant (directory) of the application for the CL [...]
+ "tenantId": { "index": 7, "kind": "parameter", "displayName": "Tenant Id",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The ID of the Microsoft
Entra tenant (directory) of the application for the CLIENT_SECRET credentia
[...]
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/azure-key-vault-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/azure-key-vault-component.adoc
index 26ca602c1327..94dda524de1f 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/azure-key-vault-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/azure-key-vault-component.adoc
@@ -50,6 +50,16 @@ include::partial$component-endpoint-headers.adoc[]
== Usage
+=== Connecting to the vault
+
+The producer connects with the `clientId`, `clientSecret` and `tenantId`
options (credential type `CLIENT_SECRET`, the
+default), with the default Azure credential chain (credential type
`AZURE_IDENTITY`), or with a `SecretClient` that you
+create yourself. When the registry holds exactly one
`com.azure.security.keyvault.secrets.SecretClient`, it is used
+without the `secretClient` option, and no credentials are needed.
+
+These options can also be set on the component, for example
`camel.component.azure-key-vault.client-id`, as the
+values that each endpoint starts from; an option set on the endpoint replaces
the value of the component.
+
=== Using Azure Key Vault Property Function
To use this function, you'll need to provide credentials to Azure Key Vault
Service as environment variables:
@@ -802,7 +812,7 @@ This could be done in the following way. You should specify
this property in you
[source,bash]
----
-camel.component.azure-key-vault.early-resolve-properties=true=true
+camel.component.azure-key-vault.early-resolve-properties=true
----
This will enable the feature, so you'll be able to resolve properties, in your
application.properties file, like:
diff --git
a/components/camel-azure/camel-azure-key-vault/src/generated/java/org/apache/camel/component/azure/key/vault/KeyVaultComponentConfigurer.java
b/components/camel-azure/camel-azure-key-vault/src/generated/java/org/apache/camel/component/azure/key/vault/KeyVaultComponentConfigurer.java
index a3f8be4fc790..99b06cb89f8e 100644
---
a/components/camel-azure/camel-azure-key-vault/src/generated/java/org/apache/camel/component/azure/key/vault/KeyVaultComponentConfigurer.java
+++
b/components/camel-azure/camel-azure-key-vault/src/generated/java/org/apache/camel/component/azure/key/vault/KeyVaultComponentConfigurer.java
@@ -20,25 +20,61 @@ import
org.apache.camel.support.component.PropertyConfigurerSupport;
@SuppressWarnings("unchecked")
public class KeyVaultComponentConfigurer extends PropertyConfigurerSupport
implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+ private org.apache.camel.component.azure.key.vault.KeyVaultConfiguration
getOrCreateConfiguration(KeyVaultComponent target) {
+ if (target.getConfiguration() == null) {
+ target.setConfiguration(new
org.apache.camel.component.azure.key.vault.KeyVaultConfiguration());
+ }
+ return target.getConfiguration();
+ }
+
@Override
public boolean configure(CamelContext camelContext, Object obj, String
name, Object value, boolean ignoreCase) {
KeyVaultComponent target = (KeyVaultComponent) obj;
switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : name) {
case "autowiredenabled":
case "autowiredEnabled":
target.setAutowiredEnabled(property(camelContext, boolean.class, value));
return true;
+ case "clientid":
+ case "clientId":
getOrCreateConfiguration(target).setClientId(property(camelContext,
java.lang.String.class, value)); return true;
+ case "clientsecret":
+ case "clientSecret":
getOrCreateConfiguration(target).setClientSecret(property(camelContext,
java.lang.String.class, value)); return true;
+ case "configuration": target.setConfiguration(property(camelContext,
org.apache.camel.component.azure.key.vault.KeyVaultConfiguration.class,
value)); return true;
+ case "credentialtype":
+ case "credentialType":
getOrCreateConfiguration(target).setCredentialType(property(camelContext,
org.apache.camel.component.azure.common.CredentialType.class, value)); return
true;
case "lazystartproducer":
case "lazyStartProducer":
target.setLazyStartProducer(property(camelContext, boolean.class, value));
return true;
+ case "operation":
getOrCreateConfiguration(target).setOperation(property(camelContext,
org.apache.camel.component.azure.key.vault.KeyVaultOperation.class, value));
return true;
+ case "secretclient":
+ case "secretClient":
getOrCreateConfiguration(target).setSecretClient(property(camelContext,
com.azure.security.keyvault.secrets.SecretClient.class, value)); return true;
+ case "tenantid":
+ case "tenantId":
getOrCreateConfiguration(target).setTenantId(property(camelContext,
java.lang.String.class, value)); return true;
default: return false;
}
}
+ @Override
+ public String[] getAutowiredNames() {
+ return new String[]{"secretClient"};
+ }
+
@Override
public Class<?> getOptionType(String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : name) {
case "autowiredenabled":
case "autowiredEnabled": return boolean.class;
+ case "clientid":
+ case "clientId": return java.lang.String.class;
+ case "clientsecret":
+ case "clientSecret": return java.lang.String.class;
+ case "configuration": return
org.apache.camel.component.azure.key.vault.KeyVaultConfiguration.class;
+ case "credentialtype":
+ case "credentialType": return
org.apache.camel.component.azure.common.CredentialType.class;
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
+ case "operation": return
org.apache.camel.component.azure.key.vault.KeyVaultOperation.class;
+ case "secretclient":
+ case "secretClient": return
com.azure.security.keyvault.secrets.SecretClient.class;
+ case "tenantid":
+ case "tenantId": return java.lang.String.class;
default: return null;
}
}
@@ -49,8 +85,20 @@ public class KeyVaultComponentConfigurer extends
PropertyConfigurerSupport imple
switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : name) {
case "autowiredenabled":
case "autowiredEnabled": return target.isAutowiredEnabled();
+ case "clientid":
+ case "clientId": return getOrCreateConfiguration(target).getClientId();
+ case "clientsecret":
+ case "clientSecret": return
getOrCreateConfiguration(target).getClientSecret();
+ case "configuration": return target.getConfiguration();
+ case "credentialtype":
+ case "credentialType": return
getOrCreateConfiguration(target).getCredentialType();
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
+ case "operation": return
getOrCreateConfiguration(target).getOperation();
+ case "secretclient":
+ case "secretClient": return
getOrCreateConfiguration(target).getSecretClient();
+ case "tenantid":
+ case "tenantId": return getOrCreateConfiguration(target).getTenantId();
default: return null;
}
}
diff --git
a/components/camel-azure/camel-azure-key-vault/src/generated/java/org/apache/camel/component/azure/key/vault/KeyVaultEndpointUriFactory.java
b/components/camel-azure/camel-azure-key-vault/src/generated/java/org/apache/camel/component/azure/key/vault/KeyVaultEndpointUriFactory.java
index 0fb0dd46f3df..7f9c23ee663a 100644
---
a/components/camel-azure/camel-azure-key-vault/src/generated/java/org/apache/camel/component/azure/key/vault/KeyVaultEndpointUriFactory.java
+++
b/components/camel-azure/camel-azure-key-vault/src/generated/java/org/apache/camel/component/azure/key/vault/KeyVaultEndpointUriFactory.java
@@ -34,10 +34,9 @@ public class KeyVaultEndpointUriFactory extends
org.apache.camel.support.compone
props.add("tenantId");
props.add("vaultName");
PROPERTY_NAMES = Collections.unmodifiableSet(props);
- Set<String> secretProps = new HashSet<>(3);
+ Set<String> secretProps = new HashSet<>(2);
secretProps.add("clientId");
secretProps.add("clientSecret");
- secretProps.add("tenantId");
SECRET_PROPERTY_NAMES = Collections.unmodifiableSet(secretProps);
ENDPOINT_IDENTITY_PROPERTY_NAMES = Collections.emptySet();
MULTI_VALUE_PREFIXES = Collections.emptyMap();
diff --git
a/components/camel-azure/camel-azure-key-vault/src/generated/resources/META-INF/org/apache/camel/component/azure/key/vault/azure-key-vault.json
b/components/camel-azure/camel-azure-key-vault/src/generated/resources/META-INF/org/apache/camel/component/azure/key/vault/azure-key-vault.json
index 23d51a65d928..6d2fd5019193 100644
---
a/components/camel-azure/camel-azure-key-vault/src/generated/resources/META-INF/org/apache/camel/component/azure/key/vault/azure-key-vault.json
+++
b/components/camel-azure/camel-azure-key-vault/src/generated/resources/META-INF/org/apache/camel/component/azure/key/vault/azure-key-vault.json
@@ -25,8 +25,15 @@
"remote": true
},
"componentProperties": {
- "lazyStartProducer": { "index": 0, "kind": "property", "displayName":
"Lazy Start Producer", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the producer should be started lazy (on the first message). By
starting lazy you can use this to allow CamelContext and routes to startup in
situations where a producer may otherwise fail [...]
- "autowiredEnabled": { "index": 1, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Whether autowiring is enabled. This is used for automatic autowiring options
(the option must be marked as autowired) by looking up in the registry to find
if there is a single instance of matching t [...]
+ "configuration": { "index": 0, "kind": "property", "displayName":
"Configuration", "group": "producer", "label": "", "required": false, "type":
"object", "javaType":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"deprecated": false, "autowired": false, "secret": false, "description": "The
configuration that each endpoint of the component starts from, as a copy. The
options of the endpoint replace its values." },
+ "credentialType": { "index": 1, "kind": "property", "displayName":
"Credential Type", "group": "common", "label": "common", "required": false,
"type": "enum", "javaType":
"org.apache.camel.component.azure.common.CredentialType", "enum": [
"CLIENT_SECRET", "AZURE_IDENTITY" ], "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "CLIENT_SECRET", "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configur [...]
+ "lazyStartProducer": { "index": 2, "kind": "property", "displayName":
"Lazy Start Producer", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the producer should be started lazy (on the first message). By
starting lazy you can use this to allow CamelContext and routes to startup in
situations where a producer may otherwise fail [...]
+ "operation": { "index": 3, "kind": "property", "displayName": "Operation",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "org.apache.camel.component.azure.key.vault.KeyVaultOperation",
"enum": [ "createSecret", "getSecret", "updateSecretProperties",
"deleteSecret", "purgeDeletedSecret" ], "deprecated": false, "autowired":
false, "secret": false, "defaultValue": "createSecret", "configurationClass":
"org.apache.camel.component.azure.key.vault [...]
+ "secretClient": { "index": 4, "kind": "property", "displayName": "Secret
Client", "group": "producer", "label": "", "required": false, "type": "object",
"javaType": "com.azure.security.keyvault.secrets.SecretClient", "deprecated":
false, "autowired": true, "secret": false, "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "To use a custom
com.azure.security.keyvault.secrets.SecretClient. Whe [...]
+ "autowiredEnabled": { "index": 5, "kind": "property", "displayName":
"Autowired Enabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Whether autowiring is enabled. This is used for automatic autowiring options
(the option must be marked as autowired) by looking up in the registry to find
if there is a single instance of matching t [...]
+ "clientId": { "index": 6, "kind": "property", "displayName": "Client Id",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The client ID
(application ID) of the Microsoft Entra application for the CLIEN [...]
+ "clientSecret": { "index": 7, "kind": "property", "displayName": "Client
Secret", "group": "security", "label": "security", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The client secret of the
Microsoft Entra application for the CLIENT_SEC [...]
+ "tenantId": { "index": 8, "kind": "property", "displayName": "Tenant Id",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The ID of the Microsoft
Entra tenant (directory) of the application for the CLIENT_SECRET credential
[...]
},
"headers": {
"CamelAzureKeyVaultProducerOperation": { "index": 0, "kind": "header",
"displayName": "", "group": "producer", "label": "producer", "required": false,
"javaType": "org.apache.camel.component.azure.key.vault.KeyVaultOperation",
"enum": [ "createSecret", "getSecret", "updateSecretProperties",
"deleteSecret", "purgeDeletedSecret" ], "deprecated": false, "autowired":
false, "secret": false, "description": "The operation that the producer
performs. It replaces the operation option.", "con [...]
@@ -45,6 +52,6 @@
"lazyStartProducer": { "index": 4, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produc [...]
"clientId": { "index": 5, "kind": "parameter", "displayName": "Client Id",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The client ID
(application ID) of the Microsoft Entra application for the CLIE [...]
"clientSecret": { "index": 6, "kind": "parameter", "displayName": "Client
Secret", "group": "security", "label": "security", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The client secret of the
Microsoft Entra application for the CLIENT_SE [...]
- "tenantId": { "index": 7, "kind": "parameter", "displayName": "Tenant Id",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The ID of the Microsoft
Entra tenant (directory) of the application for the CL [...]
+ "tenantId": { "index": 7, "kind": "parameter", "displayName": "Tenant Id",
"group": "security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "configurationClass":
"org.apache.camel.component.azure.key.vault.KeyVaultConfiguration",
"configurationField": "configuration", "description": "The ID of the Microsoft
Entra tenant (directory) of the application for the CLIENT_SECRET credentia
[...]
}
}
diff --git
a/components/camel-azure/camel-azure-key-vault/src/main/docs/azure-key-vault-component.adoc
b/components/camel-azure/camel-azure-key-vault/src/main/docs/azure-key-vault-component.adoc
index 26ca602c1327..94dda524de1f 100644
---
a/components/camel-azure/camel-azure-key-vault/src/main/docs/azure-key-vault-component.adoc
+++
b/components/camel-azure/camel-azure-key-vault/src/main/docs/azure-key-vault-component.adoc
@@ -50,6 +50,16 @@ include::partial$component-endpoint-headers.adoc[]
== Usage
+=== Connecting to the vault
+
+The producer connects with the `clientId`, `clientSecret` and `tenantId`
options (credential type `CLIENT_SECRET`, the
+default), with the default Azure credential chain (credential type
`AZURE_IDENTITY`), or with a `SecretClient` that you
+create yourself. When the registry holds exactly one
`com.azure.security.keyvault.secrets.SecretClient`, it is used
+without the `secretClient` option, and no credentials are needed.
+
+These options can also be set on the component, for example
`camel.component.azure-key-vault.client-id`, as the
+values that each endpoint starts from; an option set on the endpoint replaces
the value of the component.
+
=== Using Azure Key Vault Property Function
To use this function, you'll need to provide credentials to Azure Key Vault
Service as environment variables:
@@ -802,7 +812,7 @@ This could be done in the following way. You should specify
this property in you
[source,bash]
----
-camel.component.azure-key-vault.early-resolve-properties=true=true
+camel.component.azure-key-vault.early-resolve-properties=true
----
This will enable the feature, so you'll be able to resolve properties, in your
application.properties file, like:
diff --git
a/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultComponent.java
b/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultComponent.java
index 6cef7fe14401..94f7fe42c02d 100644
---
a/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultComponent.java
+++
b/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultComponent.java
@@ -20,7 +20,6 @@ import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
-import org.apache.camel.component.azure.common.CredentialType;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.annotations.Component;
import org.apache.camel.support.DefaultComponent;
@@ -31,7 +30,8 @@ import org.apache.camel.support.DefaultComponent;
@Component("azure-key-vault")
public class KeyVaultComponent extends DefaultComponent {
- @Metadata
+ @Metadata(description = "The configuration that each endpoint of the
component starts from, as a copy. The options of"
+ + " the endpoint replace its values.")
private KeyVaultConfiguration configuration = new KeyVaultConfiguration();
public KeyVaultComponent() {
@@ -57,13 +57,15 @@ public class KeyVaultComponent extends DefaultComponent {
final KeyVaultEndpoint endpoint = new KeyVaultEndpoint(uri, this,
epConfiguration);
setProperties(endpoint, parameters);
- if (CredentialType.CLIENT_SECRET ==
epConfiguration.getCredentialType() && epConfiguration.getSecretClient() == null
- && (epConfiguration.getClientId() == null ||
epConfiguration.getClientSecret() == null
- || epConfiguration.getTenantId() == null)) {
- throw new IllegalArgumentException(
- "Azure Secret Client or client Id, client secret and
tenant Id must be specified if credential type is set to clientSecret");
- }
-
+ // the credentials are checked when the endpoint is initialized, after
a SecretClient may have been autowired
return endpoint;
}
+
+ public KeyVaultConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(KeyVaultConfiguration configuration) {
+ this.configuration = configuration;
+ }
}
diff --git
a/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultConfiguration.java
b/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultConfiguration.java
index 17fdad667b44..495e3e39bd12 100644
---
a/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultConfiguration.java
+++
b/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultConfiguration.java
@@ -48,7 +48,7 @@ public class KeyVaultConfiguration implements Cloneable {
+ " Required for CLIENT_SECRET, the default,
unless the secretClient option is set. Not used for"
+ " AZURE_IDENTITY.")
private String clientSecret;
- @UriParam(label = "security", security = "secret",
+ @UriParam(label = "security",
description = "The ID of the Microsoft Entra tenant (directory)
of the application for the CLIENT_SECRET"
+ " credential type. Required for CLIENT_SECRET,
the default, unless the secretClient option is"
+ " set. Not used for AZURE_IDENTITY.")
diff --git
a/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultEndpoint.java
b/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultEndpoint.java
index 831cffa0aa54..46c10434c8be 100644
---
a/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultEndpoint.java
+++
b/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultEndpoint.java
@@ -97,7 +97,16 @@ public class KeyVaultEndpoint extends DefaultEndpoint
implements EndpointService
@Override
public void doInit() throws Exception {
+ // autowires a single SecretClient of the registry when the
secretClient option is not set
super.doInit();
+
+ if (CredentialType.CLIENT_SECRET == configuration.getCredentialType()
&& configuration.getSecretClient() == null
+ && (configuration.getClientId() == null ||
configuration.getClientSecret() == null
+ || configuration.getTenantId() == null)) {
+ throw new IllegalArgumentException(
+ "Azure Secret Client or client Id, client secret and
tenant Id must be specified if credential type is set to clientSecret");
+ }
+
secretClient = configuration.getSecretClient() != null
? configuration.getSecretClient() : createSecretClient();
}
diff --git
a/components/camel-azure/camel-azure-key-vault/src/test/java/org/apache/camel/component/azure/key/vault/KeyVaultConfigurationTest.java
b/components/camel-azure/camel-azure-key-vault/src/test/java/org/apache/camel/component/azure/key/vault/KeyVaultConfigurationTest.java
index b3fd42d53642..4b24ac69bcee 100644
---
a/components/camel-azure/camel-azure-key-vault/src/test/java/org/apache/camel/component/azure/key/vault/KeyVaultConfigurationTest.java
+++
b/components/camel-azure/camel-azure-key-vault/src/test/java/org/apache/camel/component/azure/key/vault/KeyVaultConfigurationTest.java
@@ -21,7 +21,9 @@ import java.util.Map;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.security.keyvault.secrets.SecretClient;
import com.azure.security.keyvault.secrets.SecretClientBuilder;
+import org.apache.camel.spi.PropertyConfigurer;
import org.apache.camel.test.junit6.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
@@ -96,11 +98,44 @@ public class KeyVaultConfigurationTest extends
CamelTestSupport {
}
@Test
- public void createEndpointFailure() throws Exception {
- Exception exception = assertThrows(IllegalArgumentException.class, ()
-> {
- KeyVaultComponent component =
context.getComponent("azure-key-vault", KeyVaultComponent.class);
- KeyVaultEndpoint endpoint = (KeyVaultEndpoint) component
- .createEndpoint("azure-key-valut://MyVault");
- });
+ public void createEndpointFailure() {
+ Exception exception = assertThrows(Exception.class, () ->
context.getEndpoint("azure-key-vault://MyVault"));
+ IllegalArgumentException cause =
ObjectHelper.getException(IllegalArgumentException.class, exception);
+ assertNotNull(cause, "IllegalArgumentException expected as cause of "
+ exception);
+ assertTrue(cause.getMessage().contains("client Id, client secret and
tenant Id must be specified"),
+ cause.getMessage());
+ }
+
+ @Test
+ public void autowiredSecretClient() {
+ SecretClient sc = new SecretClientBuilder().credential(new
DefaultAzureCredentialBuilder().build())
+ .vaultUrl("https://autowired.vault.azure.net").buildClient();
+ context.getRegistry().bind("mySecretClient", sc);
+
+ KeyVaultEndpoint endpoint =
context.getEndpoint("azure-key-vault://MyVault", KeyVaultEndpoint.class);
+
+ assertSame(sc, endpoint.getConfiguration().getSecretClient());
+ assertSame(sc, endpoint.getSecretClient());
+ assertEquals("https://autowired.vault.azure.net",
endpoint.getServiceUrl());
+ }
+
+ @Test
+ public void componentConfiguration() {
+ KeyVaultComponent component = context.getComponent("azure-key-vault",
KeyVaultComponent.class);
+ PropertyConfigurer configurer =
component.getComponentPropertyConfigurer();
+ assertTrue(configurer.configure(context, component, "clientId",
"compClient", true));
+ assertTrue(configurer.configure(context, component, "clientSecret",
"compSecret", true));
+ assertTrue(configurer.configure(context, component, "tenantId",
"compTenant", true));
+ assertTrue(configurer.configure(context, component, "operation",
"getSecret", true));
+
+ KeyVaultEndpoint endpoint =
context.getEndpoint("azure-key-vault://MyVault?operation=deleteSecret",
+ KeyVaultEndpoint.class);
+
+ assertEquals("compClient", endpoint.getConfiguration().getClientId());
+ assertEquals("compSecret",
endpoint.getConfiguration().getClientSecret());
+ assertEquals("compTenant", endpoint.getConfiguration().getTenantId());
+ // the endpoint option replaces the component value, and the component
keeps its own
+ assertEquals(KeyVaultOperation.deleteSecret,
endpoint.getConfiguration().getOperation());
+ assertEquals(KeyVaultOperation.getSecret,
component.getConfiguration().getOperation());
}
}
diff --git
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AzureKeyVaultComponentBuilderFactory.java
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AzureKeyVaultComponentBuilderFactory.java
index 1c29ede34a77..912e4bd47f4e 100644
---
a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AzureKeyVaultComponentBuilderFactory.java
+++
b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AzureKeyVaultComponentBuilderFactory.java
@@ -50,6 +50,46 @@ public interface AzureKeyVaultComponentBuilderFactory {
*/
interface AzureKeyVaultComponentBuilder extends
ComponentBuilder<KeyVaultComponent> {
+ /**
+ * The configuration that each endpoint of the component starts from,
as
+ * a copy. The options of the endpoint replace its values.
+ *
+ * The option is a:
+ *
<code>org.apache.camel.component.azure.key.vault.KeyVaultConfiguration</code>
type.
+ *
+ * Group: producer
+ *
+ * @param configuration the value to set
+ * @return the dsl builder
+ */
+ default AzureKeyVaultComponentBuilder
configuration(org.apache.camel.component.azure.key.vault.KeyVaultConfiguration
configuration) {
+ doSetProperty("configuration", configuration);
+ return this;
+ }
+
+
+ /**
+ * How the endpoint authenticates when it creates the SecretClient.
+ * CLIENT_SECRET uses the clientId, clientSecret and tenantId options.
+ * AZURE_IDENTITY uses the DefaultAzureCredential of the Azure Identity
+ * library, which tries environment variables, workload identity,
+ * managed identity and developer tools such as the Azure CLI. Not used
+ * when the secretClient option is set.
+ *
+ * The option is a:
+ *
<code>org.apache.camel.component.azure.common.CredentialType</code>
type.
+ *
+ * Default: CLIENT_SECRET
+ * Group: common
+ *
+ * @param credentialType the value to set
+ * @return the dsl builder
+ */
+ default AzureKeyVaultComponentBuilder
credentialType(org.apache.camel.component.azure.common.CredentialType
credentialType) {
+ doSetProperty("credentialType", credentialType);
+ return this;
+ }
+
/**
* Whether the producer should be started lazy (on the first message).
@@ -76,6 +116,46 @@ public interface AzureKeyVaultComponentBuilderFactory {
}
+ /**
+ * The operation that the producer performs. The
+ * CamelAzureKeyVaultProducerOperation header replaces this option.
+ * Every operation except updateSecretProperties takes the name of the
+ * secret from the CamelAzureKeyVaultSecretName header.
+ *
+ * The option is a:
+ *
<code>org.apache.camel.component.azure.key.vault.KeyVaultOperation</code>
type.
+ *
+ * Default: createSecret
+ * Group: producer
+ *
+ * @param operation the value to set
+ * @return the dsl builder
+ */
+ default AzureKeyVaultComponentBuilder
operation(org.apache.camel.component.azure.key.vault.KeyVaultOperation
operation) {
+ doSetProperty("operation", operation);
+ return this;
+ }
+
+ /**
+ * To use a custom com.azure.security.keyvault.secrets.SecretClient.
+ * When this option is set, the client decides the vault and the
+ * credentials, and the vaultName, credentialType, clientId,
+ * clientSecret and tenantId options are not used to connect.
+ *
+ * The option is a:
+ *
<code>com.azure.security.keyvault.secrets.SecretClient</code> type.
+ *
+ * Group: producer
+ *
+ * @param secretClient the value to set
+ * @return the dsl builder
+ */
+ default AzureKeyVaultComponentBuilder
secretClient(com.azure.security.keyvault.secrets.SecretClient secretClient) {
+ doSetProperty("secretClient", secretClient);
+ return this;
+ }
+
+
/**
* Whether autowiring is enabled. This is used for automatic autowiring
* options (the option must be marked as autowired) by looking up in
the
@@ -96,6 +176,60 @@ public interface AzureKeyVaultComponentBuilderFactory {
doSetProperty("autowiredEnabled", autowiredEnabled);
return this;
}
+
+ /**
+ * The client ID (application ID) of the Microsoft Entra application
for
+ * the CLIENT_SECRET credential type. Required for CLIENT_SECRET, the
+ * default, unless the secretClient option is set. Not used for
+ * AZURE_IDENTITY.
+ *
+ * The option is a: <code>java.lang.String</code> type.
+ *
+ * Group: security
+ *
+ * @param clientId the value to set
+ * @return the dsl builder
+ */
+ default AzureKeyVaultComponentBuilder clientId(java.lang.String
clientId) {
+ doSetProperty("clientId", clientId);
+ return this;
+ }
+
+ /**
+ * The client secret of the Microsoft Entra application for the
+ * CLIENT_SECRET credential type. Required for CLIENT_SECRET, the
+ * default, unless the secretClient option is set. Not used for
+ * AZURE_IDENTITY.
+ *
+ * The option is a: <code>java.lang.String</code> type.
+ *
+ * Group: security
+ *
+ * @param clientSecret the value to set
+ * @return the dsl builder
+ */
+ default AzureKeyVaultComponentBuilder clientSecret(java.lang.String
clientSecret) {
+ doSetProperty("clientSecret", clientSecret);
+ return this;
+ }
+
+ /**
+ * The ID of the Microsoft Entra tenant (directory) of the application
+ * for the CLIENT_SECRET credential type. Required for CLIENT_SECRET,
+ * the default, unless the secretClient option is set. Not used for
+ * AZURE_IDENTITY.
+ *
+ * The option is a: <code>java.lang.String</code> type.
+ *
+ * Group: security
+ *
+ * @param tenantId the value to set
+ * @return the dsl builder
+ */
+ default AzureKeyVaultComponentBuilder tenantId(java.lang.String
tenantId) {
+ doSetProperty("tenantId", tenantId);
+ return this;
+ }
}
class AzureKeyVaultComponentBuilderImpl
@@ -105,14 +239,27 @@ public interface AzureKeyVaultComponentBuilderFactory {
protected KeyVaultComponent buildConcreteComponent() {
return new KeyVaultComponent();
}
+ private
org.apache.camel.component.azure.key.vault.KeyVaultConfiguration
getOrCreateConfiguration(KeyVaultComponent component) {
+ if (component.getConfiguration() == null) {
+ component.setConfiguration(new
org.apache.camel.component.azure.key.vault.KeyVaultConfiguration());
+ }
+ return component.getConfiguration();
+ }
@Override
protected boolean setPropertyOnComponent(
Component component,
String name,
Object value) {
switch (name) {
+ case "configuration": ((KeyVaultComponent)
component).setConfiguration((org.apache.camel.component.azure.key.vault.KeyVaultConfiguration)
value); return true;
+ case "credentialType":
getOrCreateConfiguration((KeyVaultComponent)
component).setCredentialType((org.apache.camel.component.azure.common.CredentialType)
value); return true;
case "lazyStartProducer": ((KeyVaultComponent)
component).setLazyStartProducer((boolean) value); return true;
+ case "operation": getOrCreateConfiguration((KeyVaultComponent)
component).setOperation((org.apache.camel.component.azure.key.vault.KeyVaultOperation)
value); return true;
+ case "secretClient": getOrCreateConfiguration((KeyVaultComponent)
component).setSecretClient((com.azure.security.keyvault.secrets.SecretClient)
value); return true;
case "autowiredEnabled": ((KeyVaultComponent)
component).setAutowiredEnabled((boolean) value); return true;
+ case "clientId": getOrCreateConfiguration((KeyVaultComponent)
component).setClientId((java.lang.String) value); return true;
+ case "clientSecret": getOrCreateConfiguration((KeyVaultComponent)
component).setClientSecret((java.lang.String) value); return true;
+ case "tenantId": getOrCreateConfiguration((KeyVaultComponent)
component).setTenantId((java.lang.String) value); return true;
default: return false;
}
}