From 1cde312b244bfd958430a636c7b87959b4bec820 Mon Sep 17 00:00:00 2001 From: Thomas Burko Date: Sun, 10 Mar 2024 22:54:30 +0100 Subject: [PATCH] Add `fromArn` is configuration property to SNS integration (#1026) Fixes #1025 --------- Co-authored-by: Maciej Walkowiak --- docs/src/main/.DS_Store | Bin 0 -> 6148 bytes docs/src/main/asciidoc/_configprops.adoc | 5 +++-- docs/src/main/asciidoc/ses.adoc | 5 +++++ .../cloud/autoconfigure/ses/SesProperties.java | 16 ++++++++++++++++ .../ses/SimpleEmailServiceJavaMailSender.java | 11 ++++++++++- .../SimpleEmailServiceJavaMailSenderTest.java | 15 +++++++++++++++ 6 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 docs/src/main/.DS_Store diff --git a/docs/src/main/.DS_Store b/docs/src/main/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..26314ead22bb662e62a8ae0d3d6028b133b97c20 GIT binary patch literal 6148 zcmeHKyJ`bL3>+mc4$`xgh))kw^KoU0CC22 z7}qgN5Su56y>LuqhGt16Ce>=hu%t8Js;(D~iAjgm@L~02s|m&8>Ab&1IjkotN&zWw zuE2e6=idLH>3_`s=OpcaCNP^IqHNYr5Bb(cQQX3PZGGVzgs! gyd6JAQPwqI^Sl?1i9u&R=tTVtxGpj&aBT&?0j+)&cK`qY literal 0 HcmV?d00001 diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index 963c9e69c..c95f0c00c 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -7,7 +7,7 @@ |spring.cloud.aws.credentials.instance-profile | `+++false+++` | Configures an instance profile credentials provider with no further configuration. |spring.cloud.aws.credentials.profile | | The AWS profile. |spring.cloud.aws.credentials.secret-key | | The secret key to be used with a static provider. -|spring.cloud.aws.credentials.sts.async-credentials-update | | +|spring.cloud.aws.credentials.sts.async-credentials-update | | |spring.cloud.aws.credentials.sts.role-arn | | ARN of IAM role associated with STS. If not provided this will be read from {@link software.amazon.awssdk.core.SdkSystemSetting}. |spring.cloud.aws.credentials.sts.role-session-name | | Role session name that will be used by credentials provider. By default this is read from {@link software.amazon.awssdk.core.SdkSystemSetting}. |spring.cloud.aws.credentials.sts.web-identity-token-file | | Absolute path to the web identity token file that will be used by credentials provider. By default this will be read from {@link software.amazon.awssdk.core.SdkSystemSetting}. @@ -38,7 +38,7 @@ |spring.cloud.aws.parameterstore.reload.strategy | | Reload strategy to run when properties change. |spring.cloud.aws.region.instance-profile | `+++false+++` | Configures an instance profile region provider with no further configuration. |spring.cloud.aws.region.profile | | The AWS profile. -|spring.cloud.aws.region.static | | +|spring.cloud.aws.region.static | | |spring.cloud.aws.s3.accelerate-mode-enabled | | Option to enable using the accelerate endpoint when accessing S3. Accelerate endpoints allow faster transfer of objects by using Amazon CloudFront's globally distributed edge locations. |spring.cloud.aws.s3.checksum-validation-enabled | | Option to disable doing a validation of the checksum of an object stored in S3. |spring.cloud.aws.s3.chunked-encoding-enabled | | Option to enable using chunked encoding when signing the request payload for {@link software.amazon.awssdk.services.s3.model.PutObjectRequest} and {@link software.amazon.awssdk.services.s3.model.UploadPartRequest}. @@ -63,6 +63,7 @@ |spring.cloud.aws.ses.endpoint | | Overrides the default endpoint. |spring.cloud.aws.ses.region | | Overrides the default region. |spring.cloud.aws.ses.source-arn | | Configures source ARN. Used only for sending authorization. +|spring.cloud.aws.ses.from-arn | | Configures from ARN. Used only for sending authorization in the SendRawEmail operation. |spring.cloud.aws.ses.configuration-set-name | The configuration set name used for every message. |spring.cloud.aws.sns.enabled | `+++true+++` | Enables SNS integration. |spring.cloud.aws.sns.endpoint | | Overrides the default endpoint. diff --git a/docs/src/main/asciidoc/ses.adoc b/docs/src/main/asciidoc/ses.adoc index ab495ae82..213081542 100644 --- a/docs/src/main/asciidoc/ses.adoc +++ b/docs/src/main/asciidoc/ses.adoc @@ -136,6 +136,7 @@ The Spring Boot Starter for SES provides the following configuration options: | `spring.cloud.aws.ses.endpoint` | Configures endpoint used by `SesClient`. | No | | `spring.cloud.aws.ses.region` | Configures region used by `SesClient`. | No | | `spring.cloud.aws.ses.source-arn` | Configures source ARN, used only for sending authorization. | No | +| `spring.cloud.aws.ses.from-arn` | Configures from ARN, used only for sending authorization in the SendRawEmail operation. | No | | `spring.cloud.aws.ses.configuration-set-name` | The configuration set name used for every message | No | |=== @@ -148,6 +149,9 @@ an SES service where the client is overridden to use a valid region (`EU-WEST-1` `sourceArn` is the ARN of the identity that is associated with the sending authorization policy. For information about when to use this parameter, see the description see https://docs.aws.amazon.com/ses/latest/dg/sending-authorization-delegate-sender-tasks-email.html[Amazon SES Developer Guide]. +`fromArn` is the ARN of the identity that is associated with the sending authorization policy that permits you to specify a particular "From" address in the header of the raw email. +For information about when to use this parameter, see the description see https://docs.aws.amazon.com/ses/latest/dg/sending-authorization-delegate-sender-tasks-email.html[Amazon SES Developer Guide]. + `configurationSetName` sets the configuration set name on mail sender level and applies to every mail. For information about when to use this parameter, see the description https://docs.aws.amazon.com/ses/latest/dg/using-configuration-sets.html[Using configuration sets in Amazon SES]. @@ -155,6 +159,7 @@ description https://docs.aws.amazon.com/ses/latest/dg/using-configuration-sets.h ---- spring.cloud.aws.ses.region=eu-west-1 spring.cloud.aws.ses.source-arn=arn:aws:ses:eu-west-1:123456789012:identity/example.com +spring.cloud.aws.ses.from-arn=arn:aws:ses:eu-west-1:123456789012:identity/example.com spring.cloud.aws.ses.configuration-set-name=ConfigSet ---- diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/ses/SesProperties.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/ses/SesProperties.java index e7adeb98c..417d8b6d2 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/ses/SesProperties.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/ses/SesProperties.java @@ -45,6 +45,12 @@ public class SesProperties extends AwsClientProperties { @Nullable private String configurationSetName; + /** + * Configures from ARN. Only applies to SendRawEmail operation. + */ + @Nullable + private String fromArn; + @Nullable public String getSourceArn() { return sourceArn; @@ -55,6 +61,11 @@ public String getConfigurationSetName() { return configurationSetName; } + @Nullable + public String getFromArn() { + return fromArn; + } + public void setSourceArn(@Nullable String sourceArn) { this.sourceArn = sourceArn; } @@ -62,4 +73,9 @@ public void setSourceArn(@Nullable String sourceArn) { public void setConfigurationSetName(@Nullable String configurationSetName) { this.configurationSetName = configurationSetName; } + + public void setFromArn(@Nullable String fromArn) { + this.fromArn = fromArn; + } + } diff --git a/spring-cloud-aws-ses/src/main/java/io/awspring/cloud/ses/SimpleEmailServiceJavaMailSender.java b/spring-cloud-aws-ses/src/main/java/io/awspring/cloud/ses/SimpleEmailServiceJavaMailSender.java index fcb358688..9f5281c73 100644 --- a/spring-cloud-aws-ses/src/main/java/io/awspring/cloud/ses/SimpleEmailServiceJavaMailSender.java +++ b/spring-cloud-aws-ses/src/main/java/io/awspring/cloud/ses/SimpleEmailServiceJavaMailSender.java @@ -74,6 +74,9 @@ public class SimpleEmailServiceJavaMailSender extends SimpleEmailServiceMailSend @Nullable private FileTypeMap defaultFileTypeMap; + @Nullable + private String fromArn; + public SimpleEmailServiceJavaMailSender(SesClient sesClient) { this(sesClient, null); } @@ -87,6 +90,12 @@ public SimpleEmailServiceJavaMailSender(SesClient sesClient, @Nullable String so super(sesClient, sourceArn, configurationSetName); } + public SimpleEmailServiceJavaMailSender(SesClient sesClient, @Nullable String sourceArn, + @Nullable String configurationSetName, @Nullable String fromArn) { + super(sesClient, sourceArn, configurationSetName); + this.fromArn = fromArn; + } + /** * Allow Map access to the JavaMail properties of this sender, with the option to add or override specific entries. *

@@ -212,7 +221,7 @@ public void send(MimeMessage... mimeMessages) throws MailException { RawMessage rawMessage = createRawMessage(mimeMessage); SendRawEmailResponse sendRawEmailResponse = getEmailService() - .sendRawEmail(SendRawEmailRequest.builder().sourceArn(getSourceArn()) + .sendRawEmail(SendRawEmailRequest.builder().sourceArn(getSourceArn()).fromArn(this.fromArn) .configurationSetName(getConfigurationSetName()).rawMessage(rawMessage).build()); if (LOGGER.isDebugEnabled()) { diff --git a/spring-cloud-aws-ses/src/test/java/io/awspring/cloud/ses/SimpleEmailServiceJavaMailSenderTest.java b/spring-cloud-aws-ses/src/test/java/io/awspring/cloud/ses/SimpleEmailServiceJavaMailSenderTest.java index 372b946ae..527c54ab7 100644 --- a/spring-cloud-aws-ses/src/test/java/io/awspring/cloud/ses/SimpleEmailServiceJavaMailSenderTest.java +++ b/spring-cloud-aws-ses/src/test/java/io/awspring/cloud/ses/SimpleEmailServiceJavaMailSenderTest.java @@ -176,6 +176,21 @@ void testSendMimeMessageWithConfigurationSetNameSet() throws MessagingException assertThat(request.getValue().configurationSetName()).isEqualTo("Configuration Set"); } + @Test + void testSendMimeMessageWithFromArnSet() throws MessagingException { + SesClient emailService = mock(SesClient.class); + JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(emailService, null, null, + "eu-west-1:123456789012:identity/example.com"); + ArgumentCaptor request = ArgumentCaptor.forClass(SendRawEmailRequest.class); + when(emailService.sendRawEmail(request.capture())) + .thenReturn(SendRawEmailResponse.builder().messageId("123").build()); + MimeMessage mimeMessage = createMimeMessage(); + + mailSender.send(mimeMessage); + + assertThat(request.getValue().fromArn()).isEqualTo("eu-west-1:123456789012:identity/example.com"); + } + @Test void testSendMultipleMimeMessages() throws Exception { SesClient emailService = mock(SesClient.class);