org.keycloak.email.freemarker

## Class FreeMarkerEmailTemplateProvider

- java.lang.Object
- - org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider

- All Implemented Interfaces:
    EmailTemplateProvider, Provider

      public class FreeMarkerEmailTemplateProvider
      extends Object
      implements EmailTemplateProvider

  Author:
    Stian Thorgersen

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `FreeMarkerEmailTemplateProvider.EmailTemplate`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Map<String,Object>` | `attributes`
    `protected AuthenticationSessionModel` | `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.)!
    `protected FreeMarkerUtil` | `freeMarker`
    `protected RealmModel` | `realm`
    `protected KeycloakSession` | `session`
    `protected UserModel` | `user`

    - ### Fields inherited from interface org.keycloak.email.EmailTemplateProvider

      `IDENTITY_PROVIDER_BROKER_CONTEXT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FreeMarkerEmailTemplateProvider(KeycloakSession session, FreeMarkerUtil freeMarker)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addLinkInfoIntoAttributes(String link, long expirationInMinutes, Map<String,Object> attributes)` Add link info into template attributes.
    `void` | `close()`
    `protected String` | `getRealmName()`
    `protected Theme` | `getTheme()`
    `protected FreeMarkerEmailTemplateProvider.EmailTemplate` | `processTemplate(String subjectKey, List<Object> subjectAttributes, String template, Map<String,Object> attributes)`
    `protected void` | `send(Map<String,String> config, String subject, String textBody, String htmlBody)`
    `void` | `send(String subjectFormatKey, List<Object> subjectAttributes, String bodyTemplate, Map<String,Object> bodyAttributes)` Send formatted email
    `void` | `send(String subjectFormatKey, String bodyTemplate, Map<String,Object> bodyAttributes)` Send formatted email
    `protected void` | `send(String subject, String textBody, String htmlBody)`
    `void` | `sendConfirmIdentityBrokerLink(String link, long expirationInMinutes)` Send to confirm that user wants to link his account with identity broker link
    `void` | `sendEvent(Event event)`
    `void` | `sendExecuteActions(String link, long expirationInMinutes)` Change password email requested by admin
    `void` | `sendPasswordReset(String link, long expirationInMinutes)` Reset password sent from forgot password link on login
    `void` | `sendSmtpTestEmail(Map<String,String> config, UserModel user)` Test SMTP connection with current logged in user
    `void` | `sendVerifyEmail(String link, long expirationInMinutes)`
    `EmailTemplateProvider` | `setAttribute(String name, Object value)`
    `EmailTemplateProvider` | `setAuthenticationSession(AuthenticationSessionModel authenticationSession)`
    `EmailTemplateProvider` | `setRealm(RealmModel realm)`
    `EmailTemplateProvider` | `setUser(UserModel user)`
    `protected String` | `toCamelCase(EventType event)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### session

          protected KeycloakSession session

    - #### authenticationSession

          protected AuthenticationSessionModel 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

          protected FreeMarkerUtil freeMarker

    - #### realm

          protected RealmModel realm

    - #### user

          protected UserModel user

    - #### attributes

          protected final Map<String,Object> attributes

  - ### Constructor Detail

    - #### FreeMarkerEmailTemplateProvider

          public FreeMarkerEmailTemplateProvider(KeycloakSession session,
                                                 FreeMarkerUtil freeMarker)

  - ### Method Detail

    - #### setRealm

          public EmailTemplateProvider setRealm(RealmModel realm)

      Specified by:
        `setRealm` in interface `EmailTemplateProvider`

    - #### setUser

          public EmailTemplateProvider setUser(UserModel user)

      Specified by:
        `setUser` in interface `EmailTemplateProvider`

    - #### setAttribute

          public EmailTemplateProvider setAttribute(String name,
                                                    Object value)

      Specified by:
        `setAttribute` in interface `EmailTemplateProvider`

    - #### setAuthenticationSession

          public EmailTemplateProvider setAuthenticationSession(AuthenticationSessionModel authenticationSession)

      Specified by:
        `setAuthenticationSession` in interface `EmailTemplateProvider`

    - #### getRealmName

          protected String getRealmName()

    - #### sendEvent

          public void sendEvent(Event event)
                         throws EmailException

      Specified by:
        `sendEvent` in interface `EmailTemplateProvider`
      Throws:
        `EmailException`

    - #### sendPasswordReset

          public void sendPasswordReset(String link,
                                        long expirationInMinutes)
                                 throws EmailException

      Description copied from interface: `EmailTemplateProvider`
      Reset password sent from forgot password link on login
      Specified by:
        `sendPasswordReset` in interface `EmailTemplateProvider`
      Throws:
        `EmailException`

    - #### sendSmtpTestEmail

          public void sendSmtpTestEmail(Map<String,String> config,
                                        UserModel user)
                                 throws EmailException

      Description copied from interface: `EmailTemplateProvider`
      Test SMTP connection with current logged in user
      Specified by:
        `sendSmtpTestEmail` in interface `EmailTemplateProvider`
      Parameters:
        `config` - SMTP server configuration
        `user` - SMTP recipient
      Throws:
        `EmailException`

    - #### sendConfirmIdentityBrokerLink

          public void sendConfirmIdentityBrokerLink(String link,
                                                    long expirationInMinutes)
                                             throws EmailException

      Description copied from interface: `EmailTemplateProvider`
      Send to confirm that user wants to link his account with identity broker link
      Specified by:
        `sendConfirmIdentityBrokerLink` in interface `EmailTemplateProvider`
      Throws:
        `EmailException`

    - #### sendExecuteActions

          public void sendExecuteActions(String link,
                                         long expirationInMinutes)
                                  throws EmailException

      Description copied from interface: `EmailTemplateProvider`
      Change password email requested by admin
      Specified by:
        `sendExecuteActions` in interface `EmailTemplateProvider`
      Throws:
        `EmailException`

    - #### sendVerifyEmail

          public void sendVerifyEmail(String link,
                                      long expirationInMinutes)
                               throws EmailException

      Specified by:
        `sendVerifyEmail` in interface `EmailTemplateProvider`
      Throws:
        `EmailException`

    - #### addLinkInfoIntoAttributes

          protected void addLinkInfoIntoAttributes(String link,
                                                   long expirationInMinutes,
                                                   Map<String,Object> attributes)
                                            throws EmailException

      Add link info into template attributes.
      Parameters:
        `link` - to add
        `expirationInMinutes` - to add
        `attributes` - to add link info into
      Throws:
        `EmailException`

    - #### send

          public void send(String subjectFormatKey,
                           String bodyTemplate,
                           Map<String,Object> bodyAttributes)
                    throws EmailException

      Description copied from interface: `EmailTemplateProvider`
      Send formatted email
      Specified by:
        `send` in interface `EmailTemplateProvider`
      Parameters:
        `subjectFormatKey` - message property that will be used to format email subject
        `bodyTemplate` - freemarker template file
        `bodyAttributes` - 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

          protected Theme getTheme()
                            throws IOException

      Throws:
        `IOException`

    - #### send

          public void send(String subjectFormatKey,
                           List<Object> subjectAttributes,
                           String bodyTemplate,
                           Map<String,Object> bodyAttributes)
                    throws EmailException

      Description copied from interface: `EmailTemplateProvider`
      Send formatted email
      Specified by:
        `send` in interface `EmailTemplateProvider`
      Parameters:
        `subjectFormatKey` - message property that will be used to format email subject
        `subjectAttributes` - attributes used to fill subject format message
        `bodyTemplate` - freemarker template file
        `bodyAttributes` - attributes used to fill template
      Throws:
        `EmailException`

    - #### send

          protected void send(String subject,
                              String textBody,
                              String htmlBody)
                       throws EmailException

      Throws:
        `EmailException`

    - #### send

          protected void send(Map<String,String> config,
                              String subject,
                              String textBody,
                              String htmlBody)
                       throws EmailException

      Throws:
        `EmailException`

    - #### close

          public void close()

      Specified by:
        `close` in interface `Provider`

    - #### toCamelCase

          protected String toCamelCase(EventType event)

Copyright © 2020 JBoss by Red Hat. All rights reserved.