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 645e20d29686 CAMEL-28031: camel-aws2-sts - getSessionToken and
getFederationToken read their inputs (#31274)
645e20d29686 is described below
commit 645e20d29686a71fa06a52489497456a0fb7068a
Author: Andrea Cosentino <[email protected]>
AuthorDate: Thu Dec 3 14:26:27 2026 +0100
CAMEL-28031: camel-aws2-sts - getSessionToken and getFederationToken read
their inputs (#31274)
* CAMEL-28031: camel-aws2-sts - getSessionToken and getFederationToken read
their inputs
getSessionToken built GetSessionTokenRequest.builder().build() with
nothing set, so the operation always returned a
default-duration token and could not be used at all against a policy that
enforces MFA: there was no way to pass the
device and its one-time code short of pojoRequest=true.
getFederationToken set only the federated name, so its
session always had the STS default duration.
Add CamelAwsStsDurationSeconds for both operations (assumeRole keeps
CamelAwsStsAssumeRoleDurationSeconds, which is
part of the published API), and CamelAwsStsSerialNumber and
CamelAwsStsTokenCode for the MFA inputs of
getSessionToken. The two MFA headers are set together: one without the
other fails the exchange with a message that
names both, rather than letting STS reject the call.
Document the duration of each operation and the MFA flow, noting that the
one-time code should be read from the
message that carries it.
AmazonSTSClientMock now records the last request of the two operations,
so a test can assert what the producer
sends; nothing could see the request before.
* CAMEL-28031: camel-aws2-sts - getSessionToken defaults to 43200 seconds
like getFederationToken, and the MFA message says must
* CAMEL-28031: camel-aws2-sts - regenerate aws2-sts.json and its catalog
copy for the duration description
Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Andrea Cosentino <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
---
.../apache/camel/catalog/components/aws2-sts.json | 13 +++---
.../camel/catalog/docs/aws2-sts-component.adoc | 25 +++++++++++
.../apache/camel/component/aws2/sts/aws2-sts.json | 13 +++---
.../src/main/docs/aws2-sts-component.adoc | 25 +++++++++++
.../camel/component/aws2/sts/STS2Constants.java | 20 +++++++++
.../camel/component/aws2/sts/STS2Producer.java | 20 +++++++++
.../component/aws2/sts/AmazonSTSClientMock.java | 13 ++++++
.../camel/component/aws2/sts/STS2ProducerTest.java | 48 ++++++++++++++++++++++
.../endpoint/dsl/STS2EndpointBuilderFactory.java | 47 +++++++++++++++++++++
9 files changed, 214 insertions(+), 10 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-sts.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-sts.json
index ca2f9b436470..b3957cfc1f1f 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-sts.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-sts.json
@@ -49,11 +49,14 @@
"CamelAwsStsRoleSessionName": { "index": 2, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "String", "deprecated": false, "autowired": false, "secret": false,
"description": "The role session name, an identifier of 2 to 64 characters for
the assumed role session. It is part of the ARN of the assumed role user and
appears in the AWS CloudTrail logs. The assumeRole operation requires it when
pojoRequest is false.", "constantName": [...]
"CamelAwsStsFederatedName": { "index": 3, "kind": "header", "displayName":
"", "group": "producer", "label": "", "required": false, "javaType": "String",
"deprecated": false, "autowired": false, "secret": false, "description": "The
name of the federated user, 2 to 32 characters, such as Bob. The
getFederationToken operation requires it when pojoRequest is false. The
producer passes no session policy, and without one the federated user session
has no permissions except those that reso [...]
"CamelAwsStsAssumeRoleDurationSeconds": { "index": 4, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "Integer", "deprecated": false, "autowired": false, "secret":
false, "description": "The duration, in seconds, of the role session of the
assumeRole operation, from 900 up to the maximum session duration of the role
(1 to 12 hours), and at most 3600 for role chaining. A higher value fails the
operation. If not set, STS uses 3600 s [...]
- "CamelAwsStsAccessKeyId": { "index": 5, "kind": "header", "displayName":
"", "group": "assumeRole getSessionToken getFederationToken", "label":
"assumeRole getSessionToken getFederationToken", "required": false, "javaType":
"String", "deprecated": false, "autowired": false, "secret": false,
"description": "The access key ID of the temporary credentials in the body. The
producer sets it when pojoRequest is false.", "constantName":
"org.apache.camel.component.aws2.sts.STS2Constants#ACC [...]
- "CamelAwsStsSecretKey": { "index": 6, "kind": "header", "displayName": "",
"group": "assumeRole getSessionToken getFederationToken", "label": "assumeRole
getSessionToken getFederationToken", "required": false, "javaType": "String",
"deprecated": true, "deprecationNote": "The producer no longer sets this
header. Take the secret access key from the body, such as
${body.credentials().secretAccessKey()}.", "autowired": false, "secret": false,
"description": "The temporary secret access k [...]
- "CamelAwsStsSessionToken": { "index": 7, "kind": "header", "displayName":
"", "group": "assumeRole getSessionToken getFederationToken", "label":
"assumeRole getSessionToken getFederationToken", "required": false, "javaType":
"String", "deprecated": true, "deprecationNote": "The producer no longer sets
this header. Take the session token from the body, such as
${body.credentials().sessionToken()}.", "autowired": false, "secret": false,
"description": "The temporary session token. Depr [...]
- "CamelAwsStsExpiration": { "index": 8, "kind": "header", "displayName":
"", "group": "assumeRole getSessionToken getFederationToken", "label":
"assumeRole getSessionToken getFederationToken", "required": false, "javaType":
"java.time.Instant", "deprecated": false, "autowired": false, "secret": false,
"description": "The date and time at which the temporary credentials in the
body expire. The producer sets it when pojoRequest is false.", "constantName":
"org.apache.camel.component.aws [...]
- "CamelAwsStsAssumedRoleArn": { "index": 9, "kind": "header",
"displayName": "", "group": "assumeRole", "label": "assumeRole", "required":
false, "javaType": "String", "deprecated": false, "autowired": false, "secret":
false, "description": "The ARN of the assumed role user of the session, such as
arn:aws:sts::123456789012:assumed-role\/demo\/my-session, made of the role name
and the role session name. The producer sets it when pojoRequest is false.",
"constantName": "org.apache.camel [...]
+ "CamelAwsStsDurationSeconds": { "index": 5, "kind": "header",
"displayName": "", "group": "getSessionToken getFederationToken", "label":
"getSessionToken getFederationToken", "required": false, "javaType": "Integer",
"deprecated": false, "autowired": false, "secret": false, "description": "The
duration, in seconds, of the temporary credentials of the getSessionToken and
getFederationToken operations: 900 to 129600 seconds for both, 43200 (12 hours)
by default, and at most 3600 for th [...]
+ "CamelAwsStsSerialNumber": { "index": 6, "kind": "header", "displayName":
"", "group": "getSessionToken", "label": "getSessionToken", "required": false,
"javaType": "String", "deprecated": false, "autowired": false, "secret": false,
"description": "The identification number of the MFA device of the user, an ARN
for a virtual device such as arn:aws:iam::123456789012:mfa\/user, or the serial
number of a hardware device. The getSessionToken operation requires it,
together with CamelAwsS [...]
+ "CamelAwsStsTokenCode": { "index": 7, "kind": "header", "displayName": "",
"group": "getSessionToken", "label": "getSessionToken", "required": false,
"javaType": "String", "deprecated": false, "autowired": false, "secret": false,
"description": "The one-time code of the MFA device named by
CamelAwsStsSerialNumber, six digits. The getSessionToken operation requires it
when the policy of the user enforces MFA. It is used only when pojoRequest is
false.", "constantName": "org.apache.cam [...]
+ "CamelAwsStsAccessKeyId": { "index": 8, "kind": "header", "displayName":
"", "group": "assumeRole getSessionToken getFederationToken", "label":
"assumeRole getSessionToken getFederationToken", "required": false, "javaType":
"String", "deprecated": false, "autowired": false, "secret": false,
"description": "The access key ID of the temporary credentials in the body. The
producer sets it when pojoRequest is false.", "constantName":
"org.apache.camel.component.aws2.sts.STS2Constants#ACC [...]
+ "CamelAwsStsSecretKey": { "index": 9, "kind": "header", "displayName": "",
"group": "assumeRole getSessionToken getFederationToken", "label": "assumeRole
getSessionToken getFederationToken", "required": false, "javaType": "String",
"deprecated": true, "deprecationNote": "The producer no longer sets this
header. Take the secret access key from the body, such as
${body.credentials().secretAccessKey()}.", "autowired": false, "secret": false,
"description": "The temporary secret access k [...]
+ "CamelAwsStsSessionToken": { "index": 10, "kind": "header", "displayName":
"", "group": "assumeRole getSessionToken getFederationToken", "label":
"assumeRole getSessionToken getFederationToken", "required": false, "javaType":
"String", "deprecated": true, "deprecationNote": "The producer no longer sets
this header. Take the session token from the body, such as
${body.credentials().sessionToken()}.", "autowired": false, "secret": false,
"description": "The temporary session token. Dep [...]
+ "CamelAwsStsExpiration": { "index": 11, "kind": "header", "displayName":
"", "group": "assumeRole getSessionToken getFederationToken", "label":
"assumeRole getSessionToken getFederationToken", "required": false, "javaType":
"java.time.Instant", "deprecated": false, "autowired": false, "secret": false,
"description": "The date and time at which the temporary credentials in the
body expire. The producer sets it when pojoRequest is false.", "constantName":
"org.apache.camel.component.aw [...]
+ "CamelAwsStsAssumedRoleArn": { "index": 12, "kind": "header",
"displayName": "", "group": "assumeRole", "label": "assumeRole", "required":
false, "javaType": "String", "deprecated": false, "autowired": false, "secret":
false, "description": "The ARN of the assumed role user of the session, such as
arn:aws:sts::123456789012:assumed-role\/demo\/my-session, made of the role name
and the role session name. The producer sets it when pojoRequest is false.",
"constantName": "org.apache.came [...]
},
"bodyTypes": {
"producerIn": { "carriers": [ "any" ], "byOption": [ { "option":
"pojoRequest", "value": "true", "carriers": [ "pojo" ] } ], "description": "Not
used: assumeRole takes the role from the CamelAwsStsRoleArn and
CamelAwsStsRoleSessionName headers, and getFederationToken the name from
CamelAwsStsFederatedName. With pojoRequest=true the request of the AWS SDK for
the operation, such as an AssumeRoleRequest: another body fails" },
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws2-sts-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws2-sts-component.adoc
index ea67f9cc8dc8..5c441a79edee 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws2-sts-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws2-sts-component.adoc
@@ -82,6 +82,31 @@ Camel-AWS STS component provides the following operation on
the producer side:
- getSessionToken
- getFederationToken
+=== The duration of the credentials
+
+`assumeRole` takes its session length from
`CamelAwsStsAssumeRoleDurationSeconds`. `getSessionToken` and
+`getFederationToken` take theirs from `CamelAwsStsDurationSeconds` (900 to
129600 seconds; without it STS uses its own
+default of 43200 seconds, 12 hours, for both). The credentials of the account
root user are capped at 3600 seconds by
+STS. All three headers are used only when `pojoRequest` is false.
+
+=== Multi-factor authentication with getSessionToken
+
+When the policy of the user enforces MFA, `getSessionToken` needs the device
and a one-time code from it. Set both
+`CamelAwsStsSerialNumber` — the ARN of a virtual device such as
`arn:aws:iam::123456789012:mfa/user`, or the serial
+number of a hardware one — and `CamelAwsStsTokenCode`. Setting only one of the
two fails the exchange.
+
+[source,java]
+----
+from("direct:mfa")
+ .setHeader(STS2Constants.SERIAL_NUMBER,
constant("arn:aws:iam::123456789012:mfa/user"))
+ .setHeader(STS2Constants.TOKEN_CODE, header("oneTimeCode"))
+ .setHeader(STS2Constants.DURATION_SECONDS, constant(3600))
+ .to("aws2-sts://test?operation=getSessionToken");
+----
+
+The one-time code is valid once and only for a short time, so read it from the
message that carries it rather than
+storing it in the route.
+
=== The temporary credentials
The body of the message is the response of the AWS SDK, such as an
`AssumeRoleResponse`, and its `credentials()` hold
diff --git
a/components/camel-aws/camel-aws2-sts/src/generated/resources/META-INF/org/apache/camel/component/aws2/sts/aws2-sts.json
b/components/camel-aws/camel-aws2-sts/src/generated/resources/META-INF/org/apache/camel/component/aws2/sts/aws2-sts.json
index ca2f9b436470..b3957cfc1f1f 100644
---
a/components/camel-aws/camel-aws2-sts/src/generated/resources/META-INF/org/apache/camel/component/aws2/sts/aws2-sts.json
+++
b/components/camel-aws/camel-aws2-sts/src/generated/resources/META-INF/org/apache/camel/component/aws2/sts/aws2-sts.json
@@ -49,11 +49,14 @@
"CamelAwsStsRoleSessionName": { "index": 2, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "String", "deprecated": false, "autowired": false, "secret": false,
"description": "The role session name, an identifier of 2 to 64 characters for
the assumed role session. It is part of the ARN of the assumed role user and
appears in the AWS CloudTrail logs. The assumeRole operation requires it when
pojoRequest is false.", "constantName": [...]
"CamelAwsStsFederatedName": { "index": 3, "kind": "header", "displayName":
"", "group": "producer", "label": "", "required": false, "javaType": "String",
"deprecated": false, "autowired": false, "secret": false, "description": "The
name of the federated user, 2 to 32 characters, such as Bob. The
getFederationToken operation requires it when pojoRequest is false. The
producer passes no session policy, and without one the federated user session
has no permissions except those that reso [...]
"CamelAwsStsAssumeRoleDurationSeconds": { "index": 4, "kind": "header",
"displayName": "", "group": "producer", "label": "", "required": false,
"javaType": "Integer", "deprecated": false, "autowired": false, "secret":
false, "description": "The duration, in seconds, of the role session of the
assumeRole operation, from 900 up to the maximum session duration of the role
(1 to 12 hours), and at most 3600 for role chaining. A higher value fails the
operation. If not set, STS uses 3600 s [...]
- "CamelAwsStsAccessKeyId": { "index": 5, "kind": "header", "displayName":
"", "group": "assumeRole getSessionToken getFederationToken", "label":
"assumeRole getSessionToken getFederationToken", "required": false, "javaType":
"String", "deprecated": false, "autowired": false, "secret": false,
"description": "The access key ID of the temporary credentials in the body. The
producer sets it when pojoRequest is false.", "constantName":
"org.apache.camel.component.aws2.sts.STS2Constants#ACC [...]
- "CamelAwsStsSecretKey": { "index": 6, "kind": "header", "displayName": "",
"group": "assumeRole getSessionToken getFederationToken", "label": "assumeRole
getSessionToken getFederationToken", "required": false, "javaType": "String",
"deprecated": true, "deprecationNote": "The producer no longer sets this
header. Take the secret access key from the body, such as
${body.credentials().secretAccessKey()}.", "autowired": false, "secret": false,
"description": "The temporary secret access k [...]
- "CamelAwsStsSessionToken": { "index": 7, "kind": "header", "displayName":
"", "group": "assumeRole getSessionToken getFederationToken", "label":
"assumeRole getSessionToken getFederationToken", "required": false, "javaType":
"String", "deprecated": true, "deprecationNote": "The producer no longer sets
this header. Take the session token from the body, such as
${body.credentials().sessionToken()}.", "autowired": false, "secret": false,
"description": "The temporary session token. Depr [...]
- "CamelAwsStsExpiration": { "index": 8, "kind": "header", "displayName":
"", "group": "assumeRole getSessionToken getFederationToken", "label":
"assumeRole getSessionToken getFederationToken", "required": false, "javaType":
"java.time.Instant", "deprecated": false, "autowired": false, "secret": false,
"description": "The date and time at which the temporary credentials in the
body expire. The producer sets it when pojoRequest is false.", "constantName":
"org.apache.camel.component.aws [...]
- "CamelAwsStsAssumedRoleArn": { "index": 9, "kind": "header",
"displayName": "", "group": "assumeRole", "label": "assumeRole", "required":
false, "javaType": "String", "deprecated": false, "autowired": false, "secret":
false, "description": "The ARN of the assumed role user of the session, such as
arn:aws:sts::123456789012:assumed-role\/demo\/my-session, made of the role name
and the role session name. The producer sets it when pojoRequest is false.",
"constantName": "org.apache.camel [...]
+ "CamelAwsStsDurationSeconds": { "index": 5, "kind": "header",
"displayName": "", "group": "getSessionToken getFederationToken", "label":
"getSessionToken getFederationToken", "required": false, "javaType": "Integer",
"deprecated": false, "autowired": false, "secret": false, "description": "The
duration, in seconds, of the temporary credentials of the getSessionToken and
getFederationToken operations: 900 to 129600 seconds for both, 43200 (12 hours)
by default, and at most 3600 for th [...]
+ "CamelAwsStsSerialNumber": { "index": 6, "kind": "header", "displayName":
"", "group": "getSessionToken", "label": "getSessionToken", "required": false,
"javaType": "String", "deprecated": false, "autowired": false, "secret": false,
"description": "The identification number of the MFA device of the user, an ARN
for a virtual device such as arn:aws:iam::123456789012:mfa\/user, or the serial
number of a hardware device. The getSessionToken operation requires it,
together with CamelAwsS [...]
+ "CamelAwsStsTokenCode": { "index": 7, "kind": "header", "displayName": "",
"group": "getSessionToken", "label": "getSessionToken", "required": false,
"javaType": "String", "deprecated": false, "autowired": false, "secret": false,
"description": "The one-time code of the MFA device named by
CamelAwsStsSerialNumber, six digits. The getSessionToken operation requires it
when the policy of the user enforces MFA. It is used only when pojoRequest is
false.", "constantName": "org.apache.cam [...]
+ "CamelAwsStsAccessKeyId": { "index": 8, "kind": "header", "displayName":
"", "group": "assumeRole getSessionToken getFederationToken", "label":
"assumeRole getSessionToken getFederationToken", "required": false, "javaType":
"String", "deprecated": false, "autowired": false, "secret": false,
"description": "The access key ID of the temporary credentials in the body. The
producer sets it when pojoRequest is false.", "constantName":
"org.apache.camel.component.aws2.sts.STS2Constants#ACC [...]
+ "CamelAwsStsSecretKey": { "index": 9, "kind": "header", "displayName": "",
"group": "assumeRole getSessionToken getFederationToken", "label": "assumeRole
getSessionToken getFederationToken", "required": false, "javaType": "String",
"deprecated": true, "deprecationNote": "The producer no longer sets this
header. Take the secret access key from the body, such as
${body.credentials().secretAccessKey()}.", "autowired": false, "secret": false,
"description": "The temporary secret access k [...]
+ "CamelAwsStsSessionToken": { "index": 10, "kind": "header", "displayName":
"", "group": "assumeRole getSessionToken getFederationToken", "label":
"assumeRole getSessionToken getFederationToken", "required": false, "javaType":
"String", "deprecated": true, "deprecationNote": "The producer no longer sets
this header. Take the session token from the body, such as
${body.credentials().sessionToken()}.", "autowired": false, "secret": false,
"description": "The temporary session token. Dep [...]
+ "CamelAwsStsExpiration": { "index": 11, "kind": "header", "displayName":
"", "group": "assumeRole getSessionToken getFederationToken", "label":
"assumeRole getSessionToken getFederationToken", "required": false, "javaType":
"java.time.Instant", "deprecated": false, "autowired": false, "secret": false,
"description": "The date and time at which the temporary credentials in the
body expire. The producer sets it when pojoRequest is false.", "constantName":
"org.apache.camel.component.aw [...]
+ "CamelAwsStsAssumedRoleArn": { "index": 12, "kind": "header",
"displayName": "", "group": "assumeRole", "label": "assumeRole", "required":
false, "javaType": "String", "deprecated": false, "autowired": false, "secret":
false, "description": "The ARN of the assumed role user of the session, such as
arn:aws:sts::123456789012:assumed-role\/demo\/my-session, made of the role name
and the role session name. The producer sets it when pojoRequest is false.",
"constantName": "org.apache.came [...]
},
"bodyTypes": {
"producerIn": { "carriers": [ "any" ], "byOption": [ { "option":
"pojoRequest", "value": "true", "carriers": [ "pojo" ] } ], "description": "Not
used: assumeRole takes the role from the CamelAwsStsRoleArn and
CamelAwsStsRoleSessionName headers, and getFederationToken the name from
CamelAwsStsFederatedName. With pojoRequest=true the request of the AWS SDK for
the operation, such as an AssumeRoleRequest: another body fails" },
diff --git
a/components/camel-aws/camel-aws2-sts/src/main/docs/aws2-sts-component.adoc
b/components/camel-aws/camel-aws2-sts/src/main/docs/aws2-sts-component.adoc
index ea67f9cc8dc8..5c441a79edee 100644
--- a/components/camel-aws/camel-aws2-sts/src/main/docs/aws2-sts-component.adoc
+++ b/components/camel-aws/camel-aws2-sts/src/main/docs/aws2-sts-component.adoc
@@ -82,6 +82,31 @@ Camel-AWS STS component provides the following operation on
the producer side:
- getSessionToken
- getFederationToken
+=== The duration of the credentials
+
+`assumeRole` takes its session length from
`CamelAwsStsAssumeRoleDurationSeconds`. `getSessionToken` and
+`getFederationToken` take theirs from `CamelAwsStsDurationSeconds` (900 to
129600 seconds; without it STS uses its own
+default of 43200 seconds, 12 hours, for both). The credentials of the account
root user are capped at 3600 seconds by
+STS. All three headers are used only when `pojoRequest` is false.
+
+=== Multi-factor authentication with getSessionToken
+
+When the policy of the user enforces MFA, `getSessionToken` needs the device
and a one-time code from it. Set both
+`CamelAwsStsSerialNumber` — the ARN of a virtual device such as
`arn:aws:iam::123456789012:mfa/user`, or the serial
+number of a hardware one — and `CamelAwsStsTokenCode`. Setting only one of the
two fails the exchange.
+
+[source,java]
+----
+from("direct:mfa")
+ .setHeader(STS2Constants.SERIAL_NUMBER,
constant("arn:aws:iam::123456789012:mfa/user"))
+ .setHeader(STS2Constants.TOKEN_CODE, header("oneTimeCode"))
+ .setHeader(STS2Constants.DURATION_SECONDS, constant(3600))
+ .to("aws2-sts://test?operation=getSessionToken");
+----
+
+The one-time code is valid once and only for a short time, so read it from the
message that carries it rather than
+storing it in the route.
+
=== The temporary credentials
The body of the message is the response of the AWS SDK, such as an
`AssumeRoleResponse`, and its `credentials()` hold
diff --git
a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Constants.java
b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Constants.java
index 85ecbdd870a2..a62ed1581530 100644
---
a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Constants.java
+++
b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Constants.java
@@ -49,6 +49,26 @@ public interface STS2Constants {
+ " pojoRequest is false.",
javaType = "Integer")
String ASSUME_ROLE_DURATION_SECONDS =
"CamelAwsStsAssumeRoleDurationSeconds";
+ @Metadata(label = "getSessionToken getFederationToken",
+ description = "The duration, in seconds, of the temporary
credentials of the getSessionToken and"
+ + " getFederationToken operations: 900 to 129600
seconds for both, 43200 (12 hours) by default,"
+ + " and at most 3600 for the credentials of the
account root user. The assumeRole operation uses"
+ + " CamelAwsStsAssumeRoleDurationSeconds instead.
It is used only when pojoRequest is false.",
+ javaType = "Integer")
+ String DURATION_SECONDS = "CamelAwsStsDurationSeconds";
+ @Metadata(label = "getSessionToken",
+ description = "The identification number of the MFA device of
the user, an ARN for a virtual device such as"
+ + " arn:aws:iam::123456789012:mfa/user, or the
serial number of a hardware device. The"
+ + " getSessionToken operation requires it,
together with CamelAwsStsTokenCode, when the policy"
+ + " of the user enforces MFA. It is used only when
pojoRequest is false.",
+ javaType = "String")
+ String SERIAL_NUMBER = "CamelAwsStsSerialNumber";
+ @Metadata(label = "getSessionToken",
+ description = "The one-time code of the MFA device named by
CamelAwsStsSerialNumber, six digits. The"
+ + " getSessionToken operation requires it when the
policy of the user enforces MFA. It is used"
+ + " only when pojoRequest is false.",
+ javaType = "String")
+ String TOKEN_CODE = "CamelAwsStsTokenCode";
@Metadata(label = "assumeRole getSessionToken getFederationToken",
description = "The access key ID of the temporary credentials in
the body. The producer sets it when"
diff --git
a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Producer.java
b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Producer.java
index 78faf42b4eb9..61e0b140da20 100644
---
a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Producer.java
+++
b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Producer.java
@@ -166,6 +166,22 @@ public class STS2Producer extends DefaultProducer {
}
} else {
GetSessionTokenRequest.Builder builder =
GetSessionTokenRequest.builder();
+ Integer durationSeconds =
exchange.getIn().getHeader(STS2Constants.DURATION_SECONDS, Integer.class);
+ if (ObjectHelper.isNotEmpty(durationSeconds)) {
+ builder.durationSeconds(durationSeconds);
+ }
+ String serialNumber =
exchange.getIn().getHeader(STS2Constants.SERIAL_NUMBER, String.class);
+ String tokenCode =
exchange.getIn().getHeader(STS2Constants.TOKEN_CODE, String.class);
+ if (ObjectHelper.isNotEmpty(serialNumber) !=
ObjectHelper.isNotEmpty(tokenCode)) {
+ throw new IllegalArgumentException(
+ "The " + STS2Constants.SERIAL_NUMBER + " and " +
STS2Constants.TOKEN_CODE
+ + " headers of
getSessionToken must be set together, as MFA needs both the"
+ + " device and its one-time
code");
+ }
+ if (ObjectHelper.isNotEmpty(serialNumber)) {
+ builder.serialNumber(serialNumber);
+ builder.tokenCode(tokenCode);
+ }
GetSessionTokenResponse result;
try {
result = stsClient.getSessionToken(builder.build());
@@ -209,6 +225,10 @@ public class STS2Producer extends DefaultProducer {
} else {
throw new IllegalArgumentException("Federated name needs to be
specified for getFederationToken operation");
}
+ Integer federationDuration =
exchange.getIn().getHeader(STS2Constants.DURATION_SECONDS, Integer.class);
+ if (ObjectHelper.isNotEmpty(federationDuration)) {
+ builder.durationSeconds(federationDuration);
+ }
try {
result = stsClient.getFederationToken(builder.build());
} catch (AwsServiceException ase) {
diff --git
a/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/AmazonSTSClientMock.java
b/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/AmazonSTSClientMock.java
index 832f25717772..5d060889a0b6 100644
---
a/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/AmazonSTSClientMock.java
+++
b/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/AmazonSTSClientMock.java
@@ -33,9 +33,20 @@ public class AmazonSTSClientMock implements StsClient {
static final Instant EXPIRATION = Instant.parse("2026-01-01T00:00:00Z");
+ private GetSessionTokenRequest lastGetSessionTokenRequest;
+ private GetFederationTokenRequest lastGetFederationTokenRequest;
+
public AmazonSTSClientMock() {
}
+ public GetSessionTokenRequest getLastGetSessionTokenRequest() {
+ return lastGetSessionTokenRequest;
+ }
+
+ public GetFederationTokenRequest getLastGetFederationTokenRequest() {
+ return lastGetFederationTokenRequest;
+ }
+
@Override
public AssumeRoleResponse assumeRole(AssumeRoleRequest assumeRoleRequest) {
return
AssumeRoleResponse.builder().assumedRoleUser(AssumedRoleUser.builder().arn("arn").build())
@@ -46,6 +57,7 @@ public class AmazonSTSClientMock implements StsClient {
@Override
public GetSessionTokenResponse getSessionToken(GetSessionTokenRequest
getSessionTokenRequest) {
+ this.lastGetSessionTokenRequest = getSessionTokenRequest;
return GetSessionTokenResponse.builder()
.credentials(Credentials.builder().accessKeyId("xxx").secretAccessKey("yyy").sessionToken("test")
.expiration(EXPIRATION).build())
@@ -59,6 +71,7 @@ public class AmazonSTSClientMock implements StsClient {
@Override
public GetFederationTokenResponse
getFederationToken(GetFederationTokenRequest getFederationTokenRequest) {
+ this.lastGetFederationTokenRequest = getFederationTokenRequest;
return GetFederationTokenResponse.builder()
.credentials(Credentials.builder().accessKeyId("xxx").secretAccessKey("yyy").sessionToken("test")
.expiration(EXPIRATION).build())
diff --git
a/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/STS2ProducerTest.java
b/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/STS2ProducerTest.java
index 88eb7de7ae4d..17bb9af8611f 100644
---
a/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/STS2ProducerTest.java
+++
b/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/STS2ProducerTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.aws2.sts;
+import java.util.Map;
+
import org.apache.camel.BindToRegistry;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
@@ -25,7 +27,9 @@ import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.sts.model.AssumeRoleResponse;
+import software.amazon.awssdk.services.sts.model.GetFederationTokenRequest;
import software.amazon.awssdk.services.sts.model.GetFederationTokenResponse;
+import software.amazon.awssdk.services.sts.model.GetSessionTokenRequest;
import software.amazon.awssdk.services.sts.model.GetSessionTokenResponse;
import static org.assertj.core.api.Assertions.assertThat;
@@ -94,6 +98,50 @@ public class STS2ProducerTest extends CamelTestSupport {
assertEquals("xxx", resultGet.credentials().accessKeyId());
}
+ @Test
+ void getSessionTokenSendsTheDurationAndTheMfaHeaders() {
+ template.requestBodyAndHeaders("direct:getSessionToken", null, Map.of(
+ STS2Constants.DURATION_SECONDS, 7200,
+ STS2Constants.SERIAL_NUMBER,
"arn:aws:iam::123456789012:mfa/user",
+ STS2Constants.TOKEN_CODE, "123456"));
+
+ GetSessionTokenRequest request =
clientMock.getLastGetSessionTokenRequest();
+ assertThat(request.durationSeconds()).isEqualTo(7200);
+
assertThat(request.serialNumber()).isEqualTo("arn:aws:iam::123456789012:mfa/user");
+ assertThat(request.tokenCode()).isEqualTo("123456");
+ }
+
+ @Test
+ void getSessionTokenWithoutHeadersSendsAnEmptyRequest() {
+ template.requestBody("direct:getSessionToken", (Object) null);
+
+ GetSessionTokenRequest request =
clientMock.getLastGetSessionTokenRequest();
+ assertThat(request.durationSeconds()).isNull();
+ assertThat(request.serialNumber()).isNull();
+ assertThat(request.tokenCode()).isNull();
+ }
+
+ @Test
+ void getSessionTokenRejectsAnMfaDeviceWithoutItsCode() {
+ assertThatThrownBy(() ->
template.requestBodyAndHeader("direct:getSessionToken", null,
+ STS2Constants.SERIAL_NUMBER,
"arn:aws:iam::123456789012:mfa/user"))
+ .hasRootCauseInstanceOf(IllegalArgumentException.class)
+ .hasRootCauseMessage("The " + STS2Constants.SERIAL_NUMBER + "
and " + STS2Constants.TOKEN_CODE
+ + " headers of getSessionToken must be
set together, as MFA needs both the device and"
+ + " its one-time code");
+ }
+
+ @Test
+ void getFederationTokenSendsTheDuration() {
+ template.requestBodyAndHeaders("direct:getFederationToken", null,
Map.of(
+ STS2Constants.FEDERATED_NAME, "federation-account",
+ STS2Constants.DURATION_SECONDS, 3600));
+
+ GetFederationTokenRequest request =
clientMock.getLastGetFederationTokenRequest();
+ assertThat(request.name()).isEqualTo("federation-account");
+ assertThat(request.durationSeconds()).isEqualTo(3600);
+ }
+
@Test
void stsGetFederationTokenWithoutFederatedNameReportsTheCorrectOperation()
{
assertThatThrownBy(() ->
template.requestBody("direct:getFederationToken", "body"))
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/STS2EndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/STS2EndpointBuilderFactory.java
index d4f0e9c7fb22..384bc625b075 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/STS2EndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/STS2EndpointBuilderFactory.java
@@ -685,6 +685,53 @@ public interface STS2EndpointBuilderFactory {
public String awsStsAssumeRoleDurationSeconds() {
return "CamelAwsStsAssumeRoleDurationSeconds";
}
+ /**
+ * The duration, in seconds, of the temporary credentials of the
+ * getSessionToken and getFederationToken operations: 900 to 129600
+ * seconds for both, 43200 (12 hours) by default, and at most 3600 for
+ * the credentials of the account root user. The assumeRole operation
+ * uses CamelAwsStsAssumeRoleDurationSeconds instead. It is used only
+ * when pojoRequest is false.
+ *
+ * The option is a: {@code Integer} type.
+ *
+ * Group: getSessionToken getFederationToken
+ *
+ * @return the name of the header {@code AwsStsDurationSeconds}.
+ */
+ public String awsStsDurationSeconds() {
+ return "CamelAwsStsDurationSeconds";
+ }
+ /**
+ * The identification number of the MFA device of the user, an ARN for
a
+ * virtual device such as arn:aws:iam::123456789012:mfa/user, or the
+ * serial number of a hardware device. The getSessionToken operation
+ * requires it, together with CamelAwsStsTokenCode, when the policy of
+ * the user enforces MFA. It is used only when pojoRequest is false.
+ *
+ * The option is a: {@code String} type.
+ *
+ * Group: getSessionToken
+ *
+ * @return the name of the header {@code AwsStsSerialNumber}.
+ */
+ public String awsStsSerialNumber() {
+ return "CamelAwsStsSerialNumber";
+ }
+ /**
+ * The one-time code of the MFA device named by
CamelAwsStsSerialNumber,
+ * six digits. The getSessionToken operation requires it when the
policy
+ * of the user enforces MFA. It is used only when pojoRequest is false.
+ *
+ * The option is a: {@code String} type.
+ *
+ * Group: getSessionToken
+ *
+ * @return the name of the header {@code AwsStsTokenCode}.
+ */
+ public String awsStsTokenCode() {
+ return "CamelAwsStsTokenCode";
+ }
/**
* The access key ID of the temporary credentials in the body. The
* producer sets it when pojoRequest is false.