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/01/19 09:01:52 UTC
(camel) 01/02: CAMEL-20281 - Camel-AWS Components: Make it possible to use AwsSessionCredentials to support temporary credentials - AWS SQS
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch CAMEL-20281-sqs
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 28ce77df5628a7e83f4ead5739b089cf6a9d2467
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Jan 19 09:42:49 2024 +0100
CAMEL-20281 - Camel-AWS Components: Make it possible to use AwsSessionCredentials to support temporary credentials - AWS SQS
Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
.../aws2/sqs/Sqs2ComponentConfigurer.java | 12 ++
.../component/aws2/sqs/Sqs2EndpointConfigurer.java | 12 ++
.../component/aws2/sqs/Sqs2EndpointUriFactory.java | 7 +-
.../apache/camel/component/aws2/sqs/aws2-sqs.json | 16 ++-
.../camel/component/aws2/sqs/Sqs2Component.java | 3 +-
.../component/aws2/sqs/Sqs2Configuration.java | 27 ++++
.../aws2/sqs/client/Sqs2ClientFactory.java | 3 +
.../client/impl/Sqs2ClientSessionTokenImpl.java | 147 +++++++++++++++++++++
.../component/aws2/sqs/SqsClientFactoryTest.java | 9 ++
9 files changed, 227 insertions(+), 9 deletions(-)
diff --git a/components/camel-aws/camel-aws2-sqs/src/generated/java/org/apache/camel/component/aws2/sqs/Sqs2ComponentConfigurer.java b/components/camel-aws/camel-aws2-sqs/src/generated/java/org/apache/camel/component/aws2/sqs/Sqs2ComponentConfigurer.java
index 16e1635fcd7..614cee3c0ee 100644
--- a/components/camel-aws/camel-aws2-sqs/src/generated/java/org/apache/camel/component/aws2/sqs/Sqs2ComponentConfigurer.java
+++ b/components/camel-aws/camel-aws2-sqs/src/generated/java/org/apache/camel/component/aws2/sqs/Sqs2ComponentConfigurer.java
@@ -107,6 +107,8 @@ public class Sqs2ComponentConfigurer extends PropertyConfigurerSupport implement
case "secretKey": getOrCreateConfiguration(target).setSecretKey(property(camelContext, java.lang.String.class, value)); return true;
case "serversideencryptionenabled":
case "serverSideEncryptionEnabled": getOrCreateConfiguration(target).setServerSideEncryptionEnabled(property(camelContext, boolean.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":
@@ -115,6 +117,8 @@ public class Sqs2ComponentConfigurer 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;
case "visibilitytimeout":
case "visibilityTimeout": getOrCreateConfiguration(target).setVisibilityTimeout(property(camelContext, java.lang.Integer.class, value)); return true;
case "waittimeseconds":
@@ -210,6 +214,8 @@ public class Sqs2ComponentConfigurer extends PropertyConfigurerSupport implement
case "secretKey": return java.lang.String.class;
case "serversideencryptionenabled":
case "serverSideEncryptionEnabled": return boolean.class;
+ case "sessiontoken":
+ case "sessionToken": return java.lang.String.class;
case "trustallcertificates":
case "trustAllCertificates": return boolean.class;
case "uriendpointoverride":
@@ -218,6 +224,8 @@ public class Sqs2ComponentConfigurer extends PropertyConfigurerSupport implement
case "useDefaultCredentialsProvider": return boolean.class;
case "useprofilecredentialsprovider":
case "useProfileCredentialsProvider": return boolean.class;
+ case "usesessioncredentials":
+ case "useSessionCredentials": return boolean.class;
case "visibilitytimeout":
case "visibilityTimeout": return java.lang.Integer.class;
case "waittimeseconds":
@@ -309,6 +317,8 @@ public class Sqs2ComponentConfigurer extends PropertyConfigurerSupport implement
case "secretKey": return getOrCreateConfiguration(target).getSecretKey();
case "serversideencryptionenabled":
case "serverSideEncryptionEnabled": return getOrCreateConfiguration(target).isServerSideEncryptionEnabled();
+ case "sessiontoken":
+ case "sessionToken": return getOrCreateConfiguration(target).getSessionToken();
case "trustallcertificates":
case "trustAllCertificates": return getOrCreateConfiguration(target).isTrustAllCertificates();
case "uriendpointoverride":
@@ -317,6 +327,8 @@ public class Sqs2ComponentConfigurer 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();
case "visibilitytimeout":
case "visibilityTimeout": return getOrCreateConfiguration(target).getVisibilityTimeout();
case "waittimeseconds":
diff --git a/components/camel-aws/camel-aws2-sqs/src/generated/java/org/apache/camel/component/aws2/sqs/Sqs2EndpointConfigurer.java b/components/camel-aws/camel-aws2-sqs/src/generated/java/org/apache/camel/component/aws2/sqs/Sqs2EndpointConfigurer.java
index 7390a236471..4c33d2d20f4 100644
--- a/components/camel-aws/camel-aws2-sqs/src/generated/java/org/apache/camel/component/aws2/sqs/Sqs2EndpointConfigurer.java
+++ b/components/camel-aws/camel-aws2-sqs/src/generated/java/org/apache/camel/component/aws2/sqs/Sqs2EndpointConfigurer.java
@@ -124,6 +124,8 @@ public class Sqs2EndpointConfigurer extends PropertyConfigurerSupport implements
case "sendEmptyMessageWhenIdle": target.setSendEmptyMessageWhenIdle(property(camelContext, boolean.class, value)); return true;
case "serversideencryptionenabled":
case "serverSideEncryptionEnabled": target.getConfiguration().setServerSideEncryptionEnabled(property(camelContext, boolean.class, value)); return true;
+ case "sessiontoken":
+ case "sessionToken": target.getConfiguration().setSessionToken(property(camelContext, java.lang.String.class, value)); return true;
case "startscheduler":
case "startScheduler": target.setStartScheduler(property(camelContext, boolean.class, value)); return true;
case "timeunit":
@@ -138,6 +140,8 @@ public class Sqs2EndpointConfigurer extends PropertyConfigurerSupport implements
case "useFixedDelay": target.setUseFixedDelay(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;
case "visibilitytimeout":
case "visibilityTimeout": target.getConfiguration().setVisibilityTimeout(property(camelContext, java.lang.Integer.class, value)); return true;
case "waittimeseconds":
@@ -257,6 +261,8 @@ public class Sqs2EndpointConfigurer extends PropertyConfigurerSupport implements
case "sendEmptyMessageWhenIdle": return boolean.class;
case "serversideencryptionenabled":
case "serverSideEncryptionEnabled": return boolean.class;
+ case "sessiontoken":
+ case "sessionToken": return java.lang.String.class;
case "startscheduler":
case "startScheduler": return boolean.class;
case "timeunit":
@@ -271,6 +277,8 @@ public class Sqs2EndpointConfigurer extends PropertyConfigurerSupport implements
case "useFixedDelay": return boolean.class;
case "useprofilecredentialsprovider":
case "useProfileCredentialsProvider": return boolean.class;
+ case "usesessioncredentials":
+ case "useSessionCredentials": return boolean.class;
case "visibilitytimeout":
case "visibilityTimeout": return java.lang.Integer.class;
case "waittimeseconds":
@@ -386,6 +394,8 @@ public class Sqs2EndpointConfigurer extends PropertyConfigurerSupport implements
case "sendEmptyMessageWhenIdle": return target.isSendEmptyMessageWhenIdle();
case "serversideencryptionenabled":
case "serverSideEncryptionEnabled": return target.getConfiguration().isServerSideEncryptionEnabled();
+ case "sessiontoken":
+ case "sessionToken": return target.getConfiguration().getSessionToken();
case "startscheduler":
case "startScheduler": return target.isStartScheduler();
case "timeunit":
@@ -400,6 +410,8 @@ public class Sqs2EndpointConfigurer extends PropertyConfigurerSupport implements
case "useFixedDelay": return target.isUseFixedDelay();
case "useprofilecredentialsprovider":
case "useProfileCredentialsProvider": return target.getConfiguration().isUseProfileCredentialsProvider();
+ case "usesessioncredentials":
+ case "useSessionCredentials": return target.getConfiguration().isUseSessionCredentials();
case "visibilitytimeout":
case "visibilityTimeout": return target.getConfiguration().getVisibilityTimeout();
case "waittimeseconds":
diff --git a/components/camel-aws/camel-aws2-sqs/src/generated/java/org/apache/camel/component/aws2/sqs/Sqs2EndpointUriFactory.java b/components/camel-aws/camel-aws2-sqs/src/generated/java/org/apache/camel/component/aws2/sqs/Sqs2EndpointUriFactory.java
index 14c504e9e30..2d5ad365541 100644
--- a/components/camel-aws/camel-aws2-sqs/src/generated/java/org/apache/camel/component/aws2/sqs/Sqs2EndpointUriFactory.java
+++ b/components/camel-aws/camel-aws2-sqs/src/generated/java/org/apache/camel/component/aws2/sqs/Sqs2EndpointUriFactory.java
@@ -21,7 +21,7 @@ public class Sqs2EndpointUriFactory 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<>(65);
+ Set<String> props = new HashSet<>(67);
props.add("accessKey");
props.add("amazonAWSHost");
props.add("amazonSQSClient");
@@ -78,6 +78,7 @@ public class Sqs2EndpointUriFactory extends org.apache.camel.support.component.E
props.add("secretKey");
props.add("sendEmptyMessageWhenIdle");
props.add("serverSideEncryptionEnabled");
+ props.add("sessionToken");
props.add("startScheduler");
props.add("timeUnit");
props.add("trustAllCertificates");
@@ -85,13 +86,15 @@ public class Sqs2EndpointUriFactory extends org.apache.camel.support.component.E
props.add("useDefaultCredentialsProvider");
props.add("useFixedDelay");
props.add("useProfileCredentialsProvider");
+ props.add("useSessionCredentials");
props.add("visibilityTimeout");
props.add("waitTimeSeconds");
PROPERTY_NAMES = Collections.unmodifiableSet(props);
- Set<String> secretProps = new HashSet<>(3);
+ Set<String> secretProps = new HashSet<>(4);
secretProps.add("accessKey");
secretProps.add("queueOwnerAWSAccountId");
secretProps.add("secretKey");
+ secretProps.add("sessionToken");
SECRET_PROPERTY_NAMES = Collections.unmodifiableSet(secretProps);
Set<String> prefixes = new HashSet<>(1);
prefixes.add("scheduler.");
diff --git a/components/camel-aws/camel-aws2-sqs/src/generated/resources/org/apache/camel/component/aws2/sqs/aws2-sqs.json b/components/camel-aws/camel-aws2-sqs/src/generated/resources/org/apache/camel/component/aws2/sqs/aws2-sqs.json
index ae24855b494..465079e2a4e 100644
--- a/components/camel-aws/camel-aws2-sqs/src/generated/resources/org/apache/camel/component/aws2/sqs/aws2-sqs.json
+++ b/components/camel-aws/camel-aws2-sqs/src/generated/resources/org/apache/camel/component/aws2/sqs/aws2-sqs.json
@@ -68,9 +68,11 @@
"accessKey": { "index": 42, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" },
"profileCredentialsName": { "index": 43, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "If using a profile credentials provider this parameter will set the profile name" },
"secretKey": { "index": 44, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" },
- "trustAllCertificates": { "index": 45, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the endpoint" },
- "useDefaultCredentialsProvider": { "index": 46, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Set whether the SQS client should expect to load cr [...]
- "useProfileCredentialsProvider": { "index": 47, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Set whether the SQS client should expect to load cr [...]
+ "sessionToken": { "index": 45, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Amazon AWS Session Token used when the user needs to assume a IAM role" },
+ "trustAllCertificates": { "index": 46, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the endpoint" },
+ "useDefaultCredentialsProvider": { "index": 47, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Set whether the SQS client should expect to load cr [...]
+ "useProfileCredentialsProvider": { "index": 48, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Set whether the SQS client should expect to load cr [...]
+ "useSessionCredentials": { "index": 49, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Set whether the SQS client should expect to use Session Credentials. [...]
},
"headers": {
"CamelAwsSqsAttributes": { "index": 0, "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "Map<MessageSystemAttributeName, String>", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "A map of the attributes requested in ReceiveMessage to their respective values.", "constantName": "org.apache.camel.component.aws2.sqs.Sqs2Constants#ATTRIBUTES" },
@@ -145,8 +147,10 @@
"accessKey": { "index": 59, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" },
"profileCredentialsName": { "index": 60, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "If using a profile credentials provider this parameter will set the profile name" },
"secretKey": { "index": 61, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" },
- "trustAllCertificates": { "index": 62, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the endpoint" },
- "useDefaultCredentialsProvider": { "index": 63, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Set whether the SQS client should expect to load c [...]
- "useProfileCredentialsProvider": { "index": 64, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Set whether the SQS client should expect to load c [...]
+ "sessionToken": { "index": 62, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Amazon AWS Session Token used when the user needs to assume a IAM role" },
+ "trustAllCertificates": { "index": 63, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "If we want to trust all certificates in case of overriding the endpoint" },
+ "useDefaultCredentialsProvider": { "index": 64, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Set whether the SQS client should expect to load c [...]
+ "useProfileCredentialsProvider": { "index": 65, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Set whether the SQS client should expect to load c [...]
+ "useSessionCredentials": { "index": 66, "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.sqs.Sqs2Configuration", "configurationField": "configuration", "description": "Set whether the SQS client should expect to use Session Credentials [...]
}
}
diff --git a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Component.java b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Component.java
index c111df96a04..16e35cbafd6 100644
--- a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Component.java
+++ b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Component.java
@@ -65,10 +65,11 @@ public class Sqs2Component extends HealthCheckComponent {
//validation of client has to be done after endpoint initialization (in case that sqs client is autowired)
// - covered by SqsDeadletterWithClientRegistryLocalstackIT
if (!configuration.isUseDefaultCredentialsProvider() && !configuration.isUseProfileCredentialsProvider()
+ && !configuration.isUseSessionCredentials()
&& configuration.getAmazonSQSClient() == null
&& (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
throw new IllegalArgumentException(
- "useDefaultCredentialsProvider is set to false, useProfileCredentialsProvider is set to false, AmazonSQSClient or accessKey and secretKey must be specified");
+ "useDefaultCredentialsProvider is set to false, useProfileCredentialsProvider is set to false, useSessionCredentials is set to false, AmazonSQSClient or accessKey and secretKey must be specified");
}
// Verify that visibilityTimeout is set if extendMessageVisibility is
// set to true.
diff --git a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Configuration.java b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Configuration.java
index 7cef473fc54..05ad048d6f9 100644
--- a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Configuration.java
+++ b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Configuration.java
@@ -35,6 +35,8 @@ public class Sqs2Configuration implements Cloneable {
private String accessKey;
@UriParam(label = "security", secret = true)
private String secretKey;
+ @UriParam(label = "security", secret = true)
+ private String sessionToken;
@UriParam(defaultValue = "amazonaws.com")
private String amazonAWSHost = "amazonaws.com";
@UriParam(secret = true)
@@ -125,6 +127,8 @@ public class Sqs2Configuration implements Cloneable {
@UriParam(label = "security")
private boolean useProfileCredentialsProvider;
@UriParam(label = "security")
+ private boolean useSessionCredentials;
+ @UriParam(label = "security")
private String profileCredentialsName;
/**
@@ -180,6 +184,17 @@ public class Sqs2Configuration 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 boolean isDeleteAfterRead() {
return deleteAfterRead;
}
@@ -594,6 +609,18 @@ public class Sqs2Configuration implements Cloneable {
return useProfileCredentialsProvider;
}
+ public boolean isUseSessionCredentials() {
+ return useSessionCredentials;
+ }
+
+ /**
+ * Set whether the SQS 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 SQS.
+ */
+ public void setUseSessionCredentials(boolean useSessionCredentials) {
+ this.useSessionCredentials = useSessionCredentials;
+ }
+
public String getBatchSeparator() {
return batchSeparator;
}
diff --git a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/client/Sqs2ClientFactory.java b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/client/Sqs2ClientFactory.java
index 0ae106f0d90..d06021c618a 100644
--- a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/client/Sqs2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/client/Sqs2ClientFactory.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.aws2.sqs.client;
import org.apache.camel.component.aws2.sqs.Sqs2Configuration;
import org.apache.camel.component.aws2.sqs.client.impl.Sqs2ClientIAMOptimized;
import org.apache.camel.component.aws2.sqs.client.impl.Sqs2ClientIAMProfileOptimizedImpl;
+import org.apache.camel.component.aws2.sqs.client.impl.Sqs2ClientSessionTokenImpl;
import org.apache.camel.component.aws2.sqs.client.impl.Sqs2ClientStandardImpl;
/**
@@ -40,6 +41,8 @@ public final class Sqs2ClientFactory {
return new Sqs2ClientIAMOptimized(configuration);
} else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
return new Sqs2ClientIAMProfileOptimizedImpl(configuration);
+ } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
+ return new Sqs2ClientSessionTokenImpl(configuration);
} else {
return new Sqs2ClientStandardImpl(configuration);
}
diff --git a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/client/impl/Sqs2ClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/client/impl/Sqs2ClientSessionTokenImpl.java
new file mode 100644
index 00000000000..d237ab4bc22
--- /dev/null
+++ b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/client/impl/Sqs2ClientSessionTokenImpl.java
@@ -0,0 +1,147 @@
+/*
+ * 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.sqs.client.impl;
+
+import java.net.URI;
+
+import org.apache.camel.component.aws2.sqs.Sqs2Configuration;
+import org.apache.camel.component.aws2.sqs.client.Sqs2InternalClient;
+import org.apache.camel.util.FileUtil;
+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.sqs.SqsClient;
+import software.amazon.awssdk.services.sqs.SqsClientBuilder;
+import software.amazon.awssdk.utils.AttributeMap;
+
+/**
+ * Manage an AWS SQS client for all users to use. This implementation is for local instances to use a static and solid
+ * credential set.
+ */
+public class Sqs2ClientSessionTokenImpl implements Sqs2InternalClient {
+ private static final Logger LOG = LoggerFactory.getLogger(Sqs2ClientStandardImpl.class);
+ private Sqs2Configuration configuration;
+
+ /**
+ * Constructor that uses the config file.
+ */
+ public Sqs2ClientSessionTokenImpl(Sqs2Configuration configuration) {
+ LOG.trace("Creating an AWS SQS manager using static credentials.");
+ this.configuration = configuration;
+ }
+
+ /**
+ * Getting the s3 aws client that is used.
+ *
+ * @return Amazon S3 Client.
+ */
+ @Override
+ public SqsClient getSQSClient() {
+ SqsClient client = null;
+ SqsClientBuilder clientBuilder = SqsClient.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) {
+ 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 (!isDefaultAwsHost()) {
+ String endpointOverrideUri = getAwsEndpointUri();
+ clientBuilder.endpointOverride(URI.create(endpointOverrideUri));
+ }
+
+ 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;
+ }
+
+ private boolean isDefaultAwsHost() {
+ return configuration.getAmazonAWSHost().equals("amazonaws.com");
+ }
+
+ /*
+ * Gets the base endpoint for AWS (ie.: http(s)://host:port.
+ *
+ * Do not confuse with other Camel endpoint methods: this one is named after AWS'
+ * own endpoint terminology and can also be used for the endpoint override in the
+ * client builder.
+ */
+ private String getAwsEndpointUri() {
+ return configuration.getProtocol() + "://" + getFullyQualifiedAWSHost();
+ }
+
+ /*
+ * If using a different AWS host, do not assume specific parts of the AWS
+ * host and, instead, just return whatever is provided as the host.
+ */
+ private String getFullyQualifiedAWSHost() {
+ String host = configuration.getAmazonAWSHost();
+ host = FileUtil.stripTrailingSeparator(host);
+
+ if (isDefaultAwsHost()) {
+ return "sqs." + Region.of(configuration.getRegion()).id() + "." + host;
+ }
+
+ return host;
+ }
+}
diff --git a/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/SqsClientFactoryTest.java b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/SqsClientFactoryTest.java
index 0648749214c..7b9f389c14a 100644
--- a/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/SqsClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/SqsClientFactoryTest.java
@@ -20,6 +20,7 @@ import org.apache.camel.component.aws2.sqs.client.Sqs2ClientFactory;
import org.apache.camel.component.aws2.sqs.client.Sqs2InternalClient;
import org.apache.camel.component.aws2.sqs.client.impl.Sqs2ClientIAMOptimized;
import org.apache.camel.component.aws2.sqs.client.impl.Sqs2ClientIAMProfileOptimizedImpl;
+import org.apache.camel.component.aws2.sqs.client.impl.Sqs2ClientSessionTokenImpl;
import org.apache.camel.component.aws2.sqs.client.impl.Sqs2ClientStandardImpl;
import org.junit.jupiter.api.Test;
@@ -57,4 +58,12 @@ public class SqsClientFactoryTest {
Sqs2InternalClient awsssqsClient = Sqs2ClientFactory.getSqsClient(sqsConfiguration);
assertTrue(awsssqsClient instanceof Sqs2ClientIAMProfileOptimizedImpl);
}
+
+ @Test
+ public void getSessionTokenSqsClient() {
+ Sqs2Configuration sqsConfiguration = new Sqs2Configuration();
+ sqsConfiguration.setUseSessionCredentials(true);
+ Sqs2InternalClient awsssqsClient = Sqs2ClientFactory.getSqsClient(sqsConfiguration);
+ assertTrue(awsssqsClient instanceof Sqs2ClientSessionTokenImpl);
+ }
}