Package org.keycloak.email.freemarker
Class FreeMarkerEmailTemplateProvider
java.lang.Object
org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider
- All Implemented Interfaces:
EmailTemplateProvider,Provider
- Author:
- Stian Thorgersen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AuthenticationSessionModelauthenticationSession can be null for some email sendings, it is filled only for email sendings performed as part of the authentication session (email verification, password reset, broker link etc.)!protected FreeMarkerProviderprotected RealmModelprotected KeycloakSessionprotected UserModelFields inherited from interface org.keycloak.email.EmailTemplateProvider
IDENTITY_PROVIDER_BROKER_CONTEXT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddLinkInfoIntoAttributes(String link, long expirationInMinutes, Map<String, Object> attributes) Add link info into template attributes.voidclose()protected Stringprotected ThemegetTheme()processTemplate(String subjectKey, List<Object> subjectAttributes, String template, Map<String, Object> attributes) renderPasswordReset(String link, long expirationInMinutes) Builds the reset password email without sending it.protected voidvoidSend formatted emailvoidsend(String subjectFormatKey, String bodyTemplate, Map<String, Object> bodyAttributes, String destinationEmail) Send formatted email to a specific address, ignoring the user's emailvoidsend(String subjectFormatKey, List<Object> subjectAttributes, String bodyTemplate, Map<String, Object> bodyAttributes) Send formatted emailvoidsend(String subjectFormatKey, List<Object> subjectAttributes, String bodyTemplate, Map<String, Object> bodyAttributes, String address) Send formatted email to a specific address, ignoring the user's emailprotected voidprotected voidvoidsend(RenderedEmail email, int expiresAt, EmailDeliveryListener onFailed) Sends an email built by one of therendermethods, in the background after the transaction commits when possible, otherwise right away.voidsendConfirmIdentityBrokerLink(String link, long expirationInMinutes) Send to confirm that user wants to link his account with identity broker linkvoidsendEmailUpdateConfirmation(String link, long expirationInMinutes, String newEmail) voidvoidsendExecuteActions(String link, long expirationInMinutes) Change password email requested by adminvoidsendOrgInviteEmail(OrganizationModel organization, String link, long expirationInMinutes) voidsendPasswordReset(String link, long expirationInMinutes) Reset password sent from forgot password link on loginvoidsendSmtpTestEmail(Map<String, String> config, UserModel user) Test SMTP connection with current logged in uservoidsendVerifiableCredentialOffer(String link, long expirationInMinutes) voidsendVerifyEmail(String link, long expirationInMinutes) setAttribute(String name, Object value) setAuthenticationSession(AuthenticationSessionModel authenticationSession) setRealm(RealmModel realm) protected booleanThe background delivery sends through theEmailSenderProviderdirectly, which would bypass a subclass that overrides how emails are sent.protected StringtoCamelCase(EventType event)
-
Field Details
-
session
-
authenticationSession
authenticationSession can be null for some email sendings, it is filled only for email sendings performed as part of the authentication session (email verification, password reset, broker link etc.)! -
freeMarker
-
realm
-
user
-
attributes
-
-
Constructor Details
-
FreeMarkerEmailTemplateProvider
-
-
Method Details
-
setRealm
- Specified by:
setRealmin interfaceEmailTemplateProvider
-
setUser
- Specified by:
setUserin interfaceEmailTemplateProvider
-
setAttribute
- Specified by:
setAttributein interfaceEmailTemplateProvider
-
setAuthenticationSession
public EmailTemplateProvider setAuthenticationSession(AuthenticationSessionModel authenticationSession) - Specified by:
setAuthenticationSessionin interfaceEmailTemplateProvider
-
getRealmName
-
sendEvent
- Specified by:
sendEventin interfaceEmailTemplateProvider- Throws:
EmailException
-
sendPasswordReset
Description copied from interface:EmailTemplateProviderReset password sent from forgot password link on login- Specified by:
sendPasswordResetin interfaceEmailTemplateProvider- Throws:
EmailException
-
sendSmtpTestEmail
Description copied from interface:EmailTemplateProviderTest SMTP connection with current logged in user- Specified by:
sendSmtpTestEmailin interfaceEmailTemplateProvider- Parameters:
config- SMTP server configurationuser- SMTP recipient- Throws:
EmailException
-
sendConfirmIdentityBrokerLink
public void sendConfirmIdentityBrokerLink(String link, long expirationInMinutes) throws EmailException Description copied from interface:EmailTemplateProviderSend to confirm that user wants to link his account with identity broker link- Specified by:
sendConfirmIdentityBrokerLinkin interfaceEmailTemplateProvider- Throws:
EmailException
-
sendExecuteActions
Description copied from interface:EmailTemplateProviderChange password email requested by admin- Specified by:
sendExecuteActionsin interfaceEmailTemplateProvider- Throws:
EmailException
-
sendVerifiableCredentialOffer
public void sendVerifiableCredentialOffer(String link, long expirationInMinutes) throws EmailException - Specified by:
sendVerifiableCredentialOfferin interfaceEmailTemplateProvider- Throws:
EmailException
-
sendVerifyEmail
- Specified by:
sendVerifyEmailin interfaceEmailTemplateProvider- Throws:
EmailException
-
sendOrgInviteEmail
public void sendOrgInviteEmail(OrganizationModel organization, String link, long expirationInMinutes) throws EmailException - Specified by:
sendOrgInviteEmailin interfaceEmailTemplateProvider- Throws:
EmailException
-
sendEmailUpdateConfirmation
public void sendEmailUpdateConfirmation(String link, long expirationInMinutes, String newEmail) throws EmailException - Specified by:
sendEmailUpdateConfirmationin interfaceEmailTemplateProvider- Throws:
EmailException
-
addLinkInfoIntoAttributes
protected void addLinkInfoIntoAttributes(String link, long expirationInMinutes, Map<String, Object> attributes) throws EmailExceptionAdd link info into template attributes.- Parameters:
link- to addexpirationInMinutes- to addattributes- to add link info into- Throws:
EmailException
-
send
public void send(String subjectFormatKey, String bodyTemplate, Map<String, Object> bodyAttributes) throws EmailExceptionDescription copied from interface:EmailTemplateProviderSend formatted email- Specified by:
sendin interfaceEmailTemplateProvider- Parameters:
subjectFormatKey- message property that will be used to format email subjectbodyTemplate- freemarker template filebodyAttributes- attributes used to fill template- Throws:
EmailException
-
processTemplate
protected FreeMarkerEmailTemplateProvider.EmailTemplate processTemplate(String subjectKey, List<Object> subjectAttributes, String template, Map<String, Object> attributes) throws EmailException- Throws:
EmailException
-
getTheme
- Throws:
IOException
-
send
public void send(String subjectFormatKey, List<Object> subjectAttributes, String bodyTemplate, Map<String, Object> bodyAttributes) throws EmailExceptionDescription copied from interface:EmailTemplateProviderSend formatted email- Specified by:
sendin interfaceEmailTemplateProvider- Parameters:
subjectFormatKey- message property that will be used to format email subjectsubjectAttributes- attributes used to fill subject format messagebodyTemplate- freemarker template filebodyAttributes- attributes used to fill template- Throws:
EmailException
-
send
public void send(String subjectFormatKey, String bodyTemplate, Map<String, Object> bodyAttributes, String destinationEmail) throws EmailExceptionDescription copied from interface:EmailTemplateProviderSend formatted email to a specific address, ignoring the user's email- Specified by:
sendin interfaceEmailTemplateProvider- Parameters:
subjectFormatKey- message property that will be used to format email subjectbodyTemplate- freemarker template filebodyAttributes- attributes used to fill templatedestinationEmail- the email address to send the email to- Throws:
EmailException
-
send
public void send(String subjectFormatKey, List<Object> subjectAttributes, String bodyTemplate, Map<String, Object> bodyAttributes, String address) throws EmailExceptionDescription copied from interface:EmailTemplateProviderSend formatted email to a specific address, ignoring the user's email- Specified by:
sendin interfaceEmailTemplateProvider- Parameters:
subjectFormatKey- message property that will be used to format email subjectsubjectAttributes- attributes used to fill subject format messagebodyTemplate- freemarker template filebodyAttributes- attributes used to fill templateaddress- the email address to send the email to- Throws:
EmailException
-
send
protected void send(String subject, String textBody, String htmlBody, String address) throws EmailException - Throws:
EmailException
-
send
protected void send(Map<String, String> config, String subject, String textBody, String htmlBody) throws EmailException- Throws:
EmailException
-
send
protected void send(Map<String, String> config, String subject, String textBody, String htmlBody, String address) throws EmailException- Throws:
EmailException
-
renderPasswordReset
public RenderedEmail renderPasswordReset(String link, long expirationInMinutes) throws EmailException Description copied from interface:EmailTemplateProviderBuilds the reset password email without sending it. Override together withEmailTemplateProvider.send(RenderedEmail, int, EmailDeliveryListener).- Specified by:
renderPasswordResetin interfaceEmailTemplateProvider- Returns:
- the email, or
nullif this provider can only send right away - Throws:
EmailException
-
send
public void send(RenderedEmail email, int expiresAt, EmailDeliveryListener onFailed) throws EmailException Description copied from interface:EmailTemplateProviderSends an email built by one of therendermethods, in the background after the transaction commits when possible, otherwise right away.- Specified by:
sendin interfaceEmailTemplateProviderexpiresAt- time in seconds after which the email is no longer worth sending,0for no limitonFailed- called if sending in the background fails later- Throws:
EmailException
-
supportsBackgroundDelivery
protected boolean supportsBackgroundDelivery()The background delivery sends through theEmailSenderProviderdirectly, which would bypass a subclass that overrides how emails are sent. So only this class sends in the background; a subclass returns true to opt in. -
close
public void close() -
toCamelCase
-