You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2024/02/09 08:55:44 UTC
(camel) 01/01: CAMEL-20281 - Camel-AWS Components: Make it possible to use AwsSessionCredentials to support temporary credentials - AWS MSK
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch CAMEL-20281-msk
in repository https://gitbox.apache.org/repos/asf/camel.git
commit fc4ea9e5ca7a6d726c8d9fef8bdd27aa40a2d006
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Feb 9 09:55:18 2024 +0100
CAMEL-20281 - Camel-AWS Components: Make it possible to use AwsSessionCredentials to support temporary credentials - AWS MSK
Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
.../apache/camel/catalog/components/aws2-msk.json | 16 +--
.../aws2/msk/MSK2ComponentConfigurer.java | 12 +++
.../component/aws2/msk/MSK2EndpointConfigurer.java | 12 +++
.../component/aws2/msk/MSK2EndpointUriFactory.java | 7 +-
.../apache/camel/component/aws2/msk/aws2-msk.json | 16 +--
.../camel/component/aws2/msk/MSK2Component.java | 4 +-
.../component/aws2/msk/MSK2Configuration.java | 28 ++++++
.../aws2/msk/client/MSK2ClientFactory.java | 3 +
.../client/impl/MSK2ClientSessionTokenImpl.java | 111 +++++++++++++++++++++
.../component/aws2/msk/MSK2ClientFactoryTest.java | 9 ++
10 files changed, 203 insertions(+), 15 deletions(-)
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-msk.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-msk.json
index 3e574bf8515..c6beb4c0778 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-msk.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-msk.json
@@ -40,9 +40,11 @@
"accessKey": { "index": 14, "kind": "property", "displayName": "Access Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" },
"profileCredentialsName": { "index": 15, "kind": "property", "displayName": "Profile Credentials Name", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "If using a profile credentials provider this parameter will set the profile name" },
"secretKey": { "index": 16, "kind": "property", "displayName": "Secret Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" },
- "trustAllCertificates": { "index": 17, "kind": "property", "displayName": "Trust All Certificates", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the endpoint" },
- "useDefaultCredentialsProvider": { "index": 18, "kind": "property", "displayName": "Use Default Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the Kafka client should expect to load [...]
- "useProfileCredentialsProvider": { "index": 19, "kind": "property", "displayName": "Use Profile Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the MSK client should expect to load cr [...]
+ "sessionToken": { "index": 17, "kind": "property", "displayName": "Session Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Amazon AWS Session Token used when the user needs to assume a IAM role" },
+ "trustAllCertificates": { "index": 18, "kind": "property", "displayName": "Trust All Certificates", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the endpoint" },
+ "useDefaultCredentialsProvider": { "index": 19, "kind": "property", "displayName": "Use Default Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the Kafka client should expect to load [...]
+ "useProfileCredentialsProvider": { "index": 20, "kind": "property", "displayName": "Use Profile Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the MSK client should expect to load cr [...]
+ "useSessionCredentials": { "index": 21, "kind": "property", "displayName": "Use Session Credentials", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the MSK client should expect to use Session Credentials. [...]
},
"headers": {
"CamelAwsMSKOperation": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The operation we want to perform", "constantName": "org.apache.camel.component.aws2.msk.MSK2Constants#OPERATION" },
@@ -68,8 +70,10 @@
"accessKey": { "index": 11, "kind": "parameter", "displayName": "Access Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" },
"profileCredentialsName": { "index": 12, "kind": "parameter", "displayName": "Profile Credentials Name", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "If using a profile credentials provider this parameter will set the profile name" },
"secretKey": { "index": 13, "kind": "parameter", "displayName": "Secret Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" },
- "trustAllCertificates": { "index": 14, "kind": "parameter", "displayName": "Trust All Certificates", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the endpoint" },
- "useDefaultCredentialsProvider": { "index": 15, "kind": "parameter", "displayName": "Use Default Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the Kafka client should expect to load [...]
- "useProfileCredentialsProvider": { "index": 16, "kind": "parameter", "displayName": "Use Profile Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the MSK client should expect to load c [...]
+ "sessionToken": { "index": 14, "kind": "parameter", "displayName": "Session Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Amazon AWS Session Token used when the user needs to assume a IAM role" },
+ "trustAllCertificates": { "index": 15, "kind": "parameter", "displayName": "Trust All Certificates", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the endpoint" },
+ "useDefaultCredentialsProvider": { "index": 16, "kind": "parameter", "displayName": "Use Default Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the Kafka client should expect to load [...]
+ "useProfileCredentialsProvider": { "index": 17, "kind": "parameter", "displayName": "Use Profile Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the MSK client should expect to load c [...]
+ "useSessionCredentials": { "index": 18, "kind": "parameter", "displayName": "Use Session Credentials", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the MSK client should expect to use Session Credentials [...]
}
}
diff --git a/components/camel-aws/camel-aws2-msk/src/generated/java/org/apache/camel/component/aws2/msk/MSK2ComponentConfigurer.java b/components/camel-aws/camel-aws2-msk/src/generated/java/org/apache/camel/component/aws2/msk/MSK2ComponentConfigurer.java
index 6d3e058a196..53d59f41a73 100644
--- a/components/camel-aws/camel-aws2-msk/src/generated/java/org/apache/camel/component/aws2/msk/MSK2ComponentConfigurer.java
+++ b/components/camel-aws/camel-aws2-msk/src/generated/java/org/apache/camel/component/aws2/msk/MSK2ComponentConfigurer.java
@@ -57,6 +57,8 @@ public class MSK2ComponentConfigurer extends PropertyConfigurerSupport implement
case "region": getOrCreateConfiguration(target).setRegion(property(camelContext, java.lang.String.class, value)); return true;
case "secretkey":
case "secretKey": getOrCreateConfiguration(target).setSecretKey(property(camelContext, java.lang.String.class, value)); return true;
+ case "sessiontoken":
+ case "sessionToken": getOrCreateConfiguration(target).setSessionToken(property(camelContext, java.lang.String.class, value)); return true;
case "trustallcertificates":
case "trustAllCertificates": getOrCreateConfiguration(target).setTrustAllCertificates(property(camelContext, boolean.class, value)); return true;
case "uriendpointoverride":
@@ -65,6 +67,8 @@ public class MSK2ComponentConfigurer extends PropertyConfigurerSupport implement
case "useDefaultCredentialsProvider": getOrCreateConfiguration(target).setUseDefaultCredentialsProvider(property(camelContext, boolean.class, value)); return true;
case "useprofilecredentialsprovider":
case "useProfileCredentialsProvider": getOrCreateConfiguration(target).setUseProfileCredentialsProvider(property(camelContext, boolean.class, value)); return true;
+ case "usesessioncredentials":
+ case "useSessionCredentials": getOrCreateConfiguration(target).setUseSessionCredentials(property(camelContext, boolean.class, value)); return true;
default: return false;
}
}
@@ -106,6 +110,8 @@ public class MSK2ComponentConfigurer extends PropertyConfigurerSupport implement
case "region": return java.lang.String.class;
case "secretkey":
case "secretKey": return java.lang.String.class;
+ case "sessiontoken":
+ case "sessionToken": return java.lang.String.class;
case "trustallcertificates":
case "trustAllCertificates": return boolean.class;
case "uriendpointoverride":
@@ -114,6 +120,8 @@ public class MSK2ComponentConfigurer extends PropertyConfigurerSupport implement
case "useDefaultCredentialsProvider": return boolean.class;
case "useprofilecredentialsprovider":
case "useProfileCredentialsProvider": return boolean.class;
+ case "usesessioncredentials":
+ case "useSessionCredentials": return boolean.class;
default: return null;
}
}
@@ -151,6 +159,8 @@ public class MSK2ComponentConfigurer extends PropertyConfigurerSupport implement
case "region": return getOrCreateConfiguration(target).getRegion();
case "secretkey":
case "secretKey": return getOrCreateConfiguration(target).getSecretKey();
+ case "sessiontoken":
+ case "sessionToken": return getOrCreateConfiguration(target).getSessionToken();
case "trustallcertificates":
case "trustAllCertificates": return getOrCreateConfiguration(target).isTrustAllCertificates();
case "uriendpointoverride":
@@ -159,6 +169,8 @@ public class MSK2ComponentConfigurer extends PropertyConfigurerSupport implement
case "useDefaultCredentialsProvider": return getOrCreateConfiguration(target).isUseDefaultCredentialsProvider();
case "useprofilecredentialsprovider":
case "useProfileCredentialsProvider": return getOrCreateConfiguration(target).isUseProfileCredentialsProvider();
+ case "usesessioncredentials":
+ case "useSessionCredentials": return getOrCreateConfiguration(target).isUseSessionCredentials();
default: return null;
}
}
diff --git a/components/camel-aws/camel-aws2-msk/src/generated/java/org/apache/camel/component/aws2/msk/MSK2EndpointConfigurer.java b/components/camel-aws/camel-aws2-msk/src/generated/java/org/apache/camel/component/aws2/msk/MSK2EndpointConfigurer.java
index 9d920a26576..ef889a9cf6a 100644
--- a/components/camel-aws/camel-aws2-msk/src/generated/java/org/apache/camel/component/aws2/msk/MSK2EndpointConfigurer.java
+++ b/components/camel-aws/camel-aws2-msk/src/generated/java/org/apache/camel/component/aws2/msk/MSK2EndpointConfigurer.java
@@ -43,6 +43,8 @@ public class MSK2EndpointConfigurer extends PropertyConfigurerSupport implements
case "region": target.getConfiguration().setRegion(property(camelContext, java.lang.String.class, value)); return true;
case "secretkey":
case "secretKey": target.getConfiguration().setSecretKey(property(camelContext, java.lang.String.class, value)); return true;
+ case "sessiontoken":
+ case "sessionToken": target.getConfiguration().setSessionToken(property(camelContext, java.lang.String.class, value)); return true;
case "trustallcertificates":
case "trustAllCertificates": target.getConfiguration().setTrustAllCertificates(property(camelContext, boolean.class, value)); return true;
case "uriendpointoverride":
@@ -51,6 +53,8 @@ public class MSK2EndpointConfigurer extends PropertyConfigurerSupport implements
case "useDefaultCredentialsProvider": target.getConfiguration().setUseDefaultCredentialsProvider(property(camelContext, boolean.class, value)); return true;
case "useprofilecredentialsprovider":
case "useProfileCredentialsProvider": target.getConfiguration().setUseProfileCredentialsProvider(property(camelContext, boolean.class, value)); return true;
+ case "usesessioncredentials":
+ case "useSessionCredentials": target.getConfiguration().setUseSessionCredentials(property(camelContext, boolean.class, value)); return true;
default: return false;
}
}
@@ -85,6 +89,8 @@ public class MSK2EndpointConfigurer extends PropertyConfigurerSupport implements
case "region": return java.lang.String.class;
case "secretkey":
case "secretKey": return java.lang.String.class;
+ case "sessiontoken":
+ case "sessionToken": return java.lang.String.class;
case "trustallcertificates":
case "trustAllCertificates": return boolean.class;
case "uriendpointoverride":
@@ -93,6 +99,8 @@ public class MSK2EndpointConfigurer extends PropertyConfigurerSupport implements
case "useDefaultCredentialsProvider": return boolean.class;
case "useprofilecredentialsprovider":
case "useProfileCredentialsProvider": return boolean.class;
+ case "usesessioncredentials":
+ case "useSessionCredentials": return boolean.class;
default: return null;
}
}
@@ -123,6 +131,8 @@ public class MSK2EndpointConfigurer extends PropertyConfigurerSupport implements
case "region": return target.getConfiguration().getRegion();
case "secretkey":
case "secretKey": return target.getConfiguration().getSecretKey();
+ case "sessiontoken":
+ case "sessionToken": return target.getConfiguration().getSessionToken();
case "trustallcertificates":
case "trustAllCertificates": return target.getConfiguration().isTrustAllCertificates();
case "uriendpointoverride":
@@ -131,6 +141,8 @@ public class MSK2EndpointConfigurer extends PropertyConfigurerSupport implements
case "useDefaultCredentialsProvider": return target.getConfiguration().isUseDefaultCredentialsProvider();
case "useprofilecredentialsprovider":
case "useProfileCredentialsProvider": return target.getConfiguration().isUseProfileCredentialsProvider();
+ case "usesessioncredentials":
+ case "useSessionCredentials": return target.getConfiguration().isUseSessionCredentials();
default: return null;
}
}
diff --git a/components/camel-aws/camel-aws2-msk/src/generated/java/org/apache/camel/component/aws2/msk/MSK2EndpointUriFactory.java b/components/camel-aws/camel-aws2-msk/src/generated/java/org/apache/camel/component/aws2/msk/MSK2EndpointUriFactory.java
index 39a39b390fa..348aa2e50d5 100644
--- a/components/camel-aws/camel-aws2-msk/src/generated/java/org/apache/camel/component/aws2/msk/MSK2EndpointUriFactory.java
+++ b/components/camel-aws/camel-aws2-msk/src/generated/java/org/apache/camel/component/aws2/msk/MSK2EndpointUriFactory.java
@@ -21,7 +21,7 @@ public class MSK2EndpointUriFactory extends org.apache.camel.support.component.E
private static final Set<String> SECRET_PROPERTY_NAMES;
private static final Set<String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(17);
+ Set<String> props = new HashSet<>(19);
props.add("accessKey");
props.add("label");
props.add("lazyStartProducer");
@@ -35,14 +35,17 @@ public class MSK2EndpointUriFactory extends org.apache.camel.support.component.E
props.add("proxyProtocol");
props.add("region");
props.add("secretKey");
+ props.add("sessionToken");
props.add("trustAllCertificates");
props.add("uriEndpointOverride");
props.add("useDefaultCredentialsProvider");
props.add("useProfileCredentialsProvider");
+ props.add("useSessionCredentials");
PROPERTY_NAMES = Collections.unmodifiableSet(props);
- Set<String> secretProps = new HashSet<>(2);
+ Set<String> secretProps = new HashSet<>(3);
secretProps.add("accessKey");
secretProps.add("secretKey");
+ secretProps.add("sessionToken");
SECRET_PROPERTY_NAMES = Collections.unmodifiableSet(secretProps);
MULTI_VALUE_PREFIXES = Collections.emptySet();
}
diff --git a/components/camel-aws/camel-aws2-msk/src/generated/resources/org/apache/camel/component/aws2/msk/aws2-msk.json b/components/camel-aws/camel-aws2-msk/src/generated/resources/org/apache/camel/component/aws2/msk/aws2-msk.json
index 3e574bf8515..c6beb4c0778 100644
--- a/components/camel-aws/camel-aws2-msk/src/generated/resources/org/apache/camel/component/aws2/msk/aws2-msk.json
+++ b/components/camel-aws/camel-aws2-msk/src/generated/resources/org/apache/camel/component/aws2/msk/aws2-msk.json
@@ -40,9 +40,11 @@
"accessKey": { "index": 14, "kind": "property", "displayName": "Access Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" },
"profileCredentialsName": { "index": 15, "kind": "property", "displayName": "Profile Credentials Name", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "If using a profile credentials provider this parameter will set the profile name" },
"secretKey": { "index": 16, "kind": "property", "displayName": "Secret Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" },
- "trustAllCertificates": { "index": 17, "kind": "property", "displayName": "Trust All Certificates", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the endpoint" },
- "useDefaultCredentialsProvider": { "index": 18, "kind": "property", "displayName": "Use Default Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the Kafka client should expect to load [...]
- "useProfileCredentialsProvider": { "index": 19, "kind": "property", "displayName": "Use Profile Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the MSK client should expect to load cr [...]
+ "sessionToken": { "index": 17, "kind": "property", "displayName": "Session Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Amazon AWS Session Token used when the user needs to assume a IAM role" },
+ "trustAllCertificates": { "index": 18, "kind": "property", "displayName": "Trust All Certificates", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the endpoint" },
+ "useDefaultCredentialsProvider": { "index": 19, "kind": "property", "displayName": "Use Default Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the Kafka client should expect to load [...]
+ "useProfileCredentialsProvider": { "index": 20, "kind": "property", "displayName": "Use Profile Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the MSK client should expect to load cr [...]
+ "useSessionCredentials": { "index": 21, "kind": "property", "displayName": "Use Session Credentials", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the MSK client should expect to use Session Credentials. [...]
},
"headers": {
"CamelAwsMSKOperation": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The operation we want to perform", "constantName": "org.apache.camel.component.aws2.msk.MSK2Constants#OPERATION" },
@@ -68,8 +70,10 @@
"accessKey": { "index": 11, "kind": "parameter", "displayName": "Access Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" },
"profileCredentialsName": { "index": 12, "kind": "parameter", "displayName": "Profile Credentials Name", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "If using a profile credentials provider this parameter will set the profile name" },
"secretKey": { "index": 13, "kind": "parameter", "displayName": "Secret Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" },
- "trustAllCertificates": { "index": 14, "kind": "parameter", "displayName": "Trust All Certificates", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the endpoint" },
- "useDefaultCredentialsProvider": { "index": 15, "kind": "parameter", "displayName": "Use Default Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the Kafka client should expect to load [...]
- "useProfileCredentialsProvider": { "index": 16, "kind": "parameter", "displayName": "Use Profile Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the MSK client should expect to load c [...]
+ "sessionToken": { "index": 14, "kind": "parameter", "displayName": "Session Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Amazon AWS Session Token used when the user needs to assume a IAM role" },
+ "trustAllCertificates": { "index": 15, "kind": "parameter", "displayName": "Trust All Certificates", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the endpoint" },
+ "useDefaultCredentialsProvider": { "index": 16, "kind": "parameter", "displayName": "Use Default Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the Kafka client should expect to load [...]
+ "useProfileCredentialsProvider": { "index": 17, "kind": "parameter", "displayName": "Use Profile Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the MSK client should expect to load c [...]
+ "useSessionCredentials": { "index": 18, "kind": "parameter", "displayName": "Use Session Credentials", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.msk.MSK2Configuration", "configurationField": "configuration", "description": "Set whether the MSK client should expect to use Session Credentials [...]
}
}
diff --git a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Component.java b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Component.java
index a0d0b8e29a2..63d2a5c383d 100644
--- a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Component.java
+++ b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Component.java
@@ -47,7 +47,9 @@ public class MSK2Component extends HealthCheckComponent {
MSK2Endpoint endpoint = new MSK2Endpoint(uri, this, configuration);
setProperties(endpoint, parameters);
if (Boolean.FALSE.equals(configuration.isUseDefaultCredentialsProvider())
- && Boolean.FALSE.equals(configuration.isUseProfileCredentialsProvider()) && configuration.getMskClient() == null
+ && Boolean.FALSE.equals(configuration.isUseProfileCredentialsProvider())
+ && Boolean.FALSE.equals(configuration.isUseSessionCredentials())
+ && configuration.getMskClient() == null
&& (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
throw new IllegalArgumentException(
"useDefaultCredentialsProvider is set to false, useProfileCredentialsProvider is set to false, Amazon msk client or accessKey and secretKey must be specified");
diff --git a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Configuration.java b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Configuration.java
index 143f50e9b18..4aa6de92601 100644
--- a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Configuration.java
+++ b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Configuration.java
@@ -37,6 +37,9 @@ public class MSK2Configuration implements Cloneable {
private String accessKey;
@UriParam(label = "security", secret = true)
private String secretKey;
+
+ @UriParam(label = "security", secret = true)
+ private String sessionToken;
@UriParam
@Metadata(required = true)
private MSK2Operations operation;
@@ -61,6 +64,8 @@ public class MSK2Configuration implements Cloneable {
@UriParam(label = "security")
private boolean useProfileCredentialsProvider;
@UriParam(label = "security")
+ private boolean useSessionCredentials;
+ @UriParam(label = "security")
private String profileCredentialsName;
public KafkaClient getMskClient() {
@@ -96,6 +101,17 @@ public class MSK2Configuration implements Cloneable {
this.secretKey = secretKey;
}
+ public String getSessionToken() {
+ return sessionToken;
+ }
+
+ /**
+ * Amazon AWS Session Token used when the user needs to assume a IAM role
+ */
+ public void setSessionToken(String sessionToken) {
+ this.sessionToken = sessionToken;
+ }
+
public MSK2Operations getOperation() {
return operation;
}
@@ -220,6 +236,18 @@ public class MSK2Configuration implements Cloneable {
this.useProfileCredentialsProvider = useProfileCredentialsProvider;
}
+ public boolean isUseSessionCredentials() {
+ return useSessionCredentials;
+ }
+
+ /**
+ * Set whether the MSK client should expect to use Session Credentials. This is useful in situation in which the
+ * user needs to assume a IAM role for doing operations in MSK.
+ */
+ public void setUseSessionCredentials(boolean useSessionCredentials) {
+ this.useSessionCredentials = useSessionCredentials;
+ }
+
public String getProfileCredentialsName() {
return profileCredentialsName;
}
diff --git a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/MSK2ClientFactory.java b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/MSK2ClientFactory.java
index 31ca559eeec..a344541f508 100644
--- a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/MSK2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/MSK2ClientFactory.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.aws2.msk.client;
import org.apache.camel.component.aws2.msk.MSK2Configuration;
import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientOptimizedImpl;
import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientProfileOptimizedImpl;
+import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientSessionTokenImpl;
import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientStandardImpl;
/**
@@ -40,6 +41,8 @@ public final class MSK2ClientFactory {
return new MSK2ClientOptimizedImpl(configuration);
} else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
return new MSK2ClientProfileOptimizedImpl(configuration);
+ } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
+ return new MSK2ClientSessionTokenImpl(configuration);
} else {
return new MSK2ClientStandardImpl(configuration);
}
diff --git a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientSessionTokenImpl.java
new file mode 100644
index 00000000000..e146cbad9a7
--- /dev/null
+++ b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientSessionTokenImpl.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws2.msk.client.impl;
+
+import java.net.URI;
+
+import org.apache.camel.component.aws2.msk.MSK2Configuration;
+import org.apache.camel.component.aws2.msk.client.MSK2InternalClient;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.http.SdkHttpClient;
+import software.amazon.awssdk.http.SdkHttpConfigurationOption;
+import software.amazon.awssdk.http.apache.ApacheHttpClient;
+import software.amazon.awssdk.http.apache.ProxyConfiguration;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.kafka.KafkaClient;
+import software.amazon.awssdk.services.kafka.KafkaClientBuilder;
+import software.amazon.awssdk.utils.AttributeMap;
+
+/**
+ * Manage an AWS MQ client for all users to use. This implementation is for local instances to use a static and solid
+ * credential set.
+ */
+public class MSK2ClientSessionTokenImpl implements MSK2InternalClient {
+ private static final Logger LOG = LoggerFactory.getLogger(MSK2ClientSessionTokenImpl.class);
+ private MSK2Configuration configuration;
+
+ /**
+ * Constructor that uses the config file.
+ */
+ public MSK2ClientSessionTokenImpl(MSK2Configuration configuration) {
+ LOG.trace("Creating an AWS MSK manager using static credentials.");
+ this.configuration = configuration;
+ }
+
+ /**
+ * Getting the MQ AWS client that is used.
+ *
+ * @return Amazon MQ Client.
+ */
+ @Override
+ public KafkaClient getKafkaClient() {
+ KafkaClient client = null;
+ KafkaClientBuilder clientBuilder = KafkaClient.builder();
+ ProxyConfiguration.Builder proxyConfig = null;
+ ApacheHttpClient.Builder httpClientBuilder = null;
+ boolean isClientConfigFound = false;
+ if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
+ proxyConfig = ProxyConfiguration.builder();
+ URI proxyEndpoint = URI.create(configuration.getProxyProtocol() + "://" + configuration.getProxyHost() + ":"
+ + configuration.getProxyPort());
+ proxyConfig.endpoint(proxyEndpoint);
+ httpClientBuilder = ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build());
+ isClientConfigFound = true;
+ }
+ if (configuration.getAccessKey() != null && configuration.getSecretKey() != null
+ && configuration.getSessionToken() != null) {
+ AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
+ configuration.getSecretKey(), configuration.getSessionToken());
+ if (isClientConfigFound) {
+ clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder)
+ .credentialsProvider(StaticCredentialsProvider.create(cred));
+ } else {
+ clientBuilder = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred));
+ }
+ } else {
+ if (!isClientConfigFound) {
+ clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
+ }
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
+ clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
+ }
+ if (configuration.isOverrideEndpoint()) {
+ clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
+ }
+ if (configuration.isTrustAllCertificates()) {
+ if (httpClientBuilder == null) {
+ httpClientBuilder = ApacheHttpClient.builder();
+ }
+ SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
+ .builder()
+ .put(
+ SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
+ Boolean.TRUE)
+ .build());
+ // set created http client to use instead of builder
+ clientBuilder.httpClient(ahc);
+ clientBuilder.httpClientBuilder(null);
+ }
+ client = clientBuilder.build();
+ return client;
+ }
+}
diff --git a/components/camel-aws/camel-aws2-msk/src/test/java/org/apache/camel/component/aws2/msk/MSK2ClientFactoryTest.java b/components/camel-aws/camel-aws2-msk/src/test/java/org/apache/camel/component/aws2/msk/MSK2ClientFactoryTest.java
index 4edc0ee64b3..be2467ea8ea 100644
--- a/components/camel-aws/camel-aws2-msk/src/test/java/org/apache/camel/component/aws2/msk/MSK2ClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-msk/src/test/java/org/apache/camel/component/aws2/msk/MSK2ClientFactoryTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.aws2.msk;
import org.apache.camel.component.aws2.msk.client.MSK2ClientFactory;
import org.apache.camel.component.aws2.msk.client.MSK2InternalClient;
import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientOptimizedImpl;
+import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientSessionTokenImpl;
import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientStandardImpl;
import org.junit.jupiter.api.Test;
@@ -48,4 +49,12 @@ public class MSK2ClientFactoryTest {
MSK2InternalClient mskClient = MSK2ClientFactory.getKafkaClient(msk2Configuration);
assertTrue(mskClient instanceof MSK2ClientOptimizedImpl);
}
+
+ @Test
+ public void getMSKSessionTokenClient() {
+ MSK2Configuration msk2Configuration = new MSK2Configuration();
+ msk2Configuration.setUseSessionCredentials(true);
+ MSK2InternalClient mskClient = MSK2ClientFactory.getKafkaClient(msk2Configuration);
+ assertTrue(mskClient instanceof MSK2ClientSessionTokenImpl);
+ }
}