Class ThymeleafOttMailer
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.mail.ThymeleafOttMailer
- All Implemented Interfaces:
OttDelivery
OttDelivery that e-mails one-time codes and magic links as multipart messages (plain text and HTML)
rendered with Thymeleaf. Only OttChannel.EMAIL is handled: asking it to deliver through another channel is
a programming error and is refused with an IllegalArgumentException, so a token is never silently dropped.
Subject and texts come from a MessageSource resolved with the explicitly configured locale, never the
platform's default. A delivery failure becomes an OttDeliveryException with a generic message and a
sanitized cause: neither the address, nor the code, nor the link is ever logged or carried by an exception.-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final StringMessage key of the subject of the code message.(package private) static final StringTemplate of the code message (without extension).(package private) static final StringTemplate variable holding the code.(package private) static final StringGeneric message of every delivery failure.(package private) static final StringExtension of the HTML templates.(package private) static final StringMessage key of the subject of the link message.(package private) static final StringTemplate of the link message (without extension).(package private) static final StringTemplate variable holding the link.private final org.springframework.mail.javamail.JavaMailSenderSends the messages.private final org.springframework.context.MessageSourceSource of the subjects.private final MailPropertiesSender, base URL and locale.private static final longSeconds in a minute.private final org.thymeleaf.TemplateEngineRenders the templates; private to this mailer.(package private) static final StringExtension of the plain-text templates.(package private) static final StringTemplate variable holding the validity in minutes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddeliverCode(OttChannel channel, String destination, String code, Duration validFor) Delivers a numeric code.voiddeliverLink(OttChannel channel, String destination, URI link, Duration validFor) Delivers a magic link.private static longRounds a duration up to whole minutes, at least one.private static voidrequireEmail(OttChannel channel) Refuses a channel other than e-mail.private voidsend(String destination, String subjectKey, String template, String variable, String value, Duration validFor) Renders and sends one message.
-
Field Details
-
CODE_TEMPLATE
Template of the code message (without extension).- See Also:
-
LINK_TEMPLATE
Template of the link message (without extension).- See Also:
-
HTML_EXTENSION
Extension of the HTML templates.- See Also:
-
TEXT_EXTENSION
Extension of the plain-text templates.- See Also:
-
CODE_SUBJECT
Message key of the subject of the code message.- See Also:
-
LINK_SUBJECT
Message key of the subject of the link message.- See Also:
-
CODE_VARIABLE
Template variable holding the code.- See Also:
-
LINK_VARIABLE
Template variable holding the link.- See Also:
-
VALID_MINUTES_VARIABLE
Template variable holding the validity in minutes.- See Also:
-
FAILURE_MESSAGE
Generic message of every delivery failure.- See Also:
-
SECONDS_PER_MINUTE
private static final long SECONDS_PER_MINUTESeconds in a minute.- See Also:
-
mailSender
private final org.springframework.mail.javamail.JavaMailSender mailSenderSends the messages. -
templateEngine
private final org.thymeleaf.TemplateEngine templateEngineRenders the templates; private to this mailer. -
messageSource
private final org.springframework.context.MessageSource messageSourceSource of the subjects. -
properties
Sender, base URL and locale.
-
-
Constructor Details
-
ThymeleafOttMailer
public ThymeleafOttMailer()
-
-
Method Details
-
deliverCode
Description copied from interface:OttDeliveryDelivers a numeric code.- Specified by:
deliverCodein interfaceOttDelivery- Parameters:
channel- channel to use.destination- e-mail address or E.164 phone number, according to the channel.code- the code in clear text.validFor- how long the code stays valid, shown to the user.
-
deliverLink
Description copied from interface:OttDeliveryDelivers a magic link.- Specified by:
deliverLinkin interfaceOttDelivery- Parameters:
channel- channel to use.destination- e-mail address or E.164 phone number, according to the channel.link- the link that opens the confirmation page.validFor- how long the link stays valid, shown to the user.
-
send
private void send(String destination, String subjectKey, String template, String variable, String value, Duration validFor) Renders and sends one message.- Parameters:
destination- recipient address.subjectKey- message key of the subject.template- template name without extension.variable- name of the variable that holds the secret value.value- the code or link.validFor- validity shown to the user.- Throws:
OttDeliveryException- if the message cannot be rendered or delivered.
-
minutes
Rounds a duration up to whole minutes, at least one.- Parameters:
validFor- the validity.- Returns:
- the minutes to show.
-
requireEmail
Refuses a channel other than e-mail.- Parameters:
channel- requested channel.- Throws:
IllegalArgumentException- if the channel is notOttChannel.EMAIL.
-