keycloak-service
クラス | 公開メンバ関数 | 限定公開メンバ関数 | 限定公開変数類 | 全メンバ一覧
org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider クラス
org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider の継承関係図
Inheritance graph
org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider 連携図
Collaboration graph

クラス

class  EmailTemplate
 

公開メンバ関数

 FreeMarkerEmailTemplateProvider (KeycloakSession session, FreeMarkerUtil freeMarker)
 
EmailTemplateProvider setRealm (RealmModel realm)
 
EmailTemplateProvider setUser (UserModel user)
 
EmailTemplateProvider setAttribute (String name, Object value)
 
EmailTemplateProvider setAuthenticationSession (AuthenticationSessionModel authenticationSession)
 
void sendEvent (Event event) throws EmailException
 
void sendPasswordReset (String link, long expirationInMinutes) throws EmailException
 
void sendSmtpTestEmail (Map< String, String > config, UserModel user) throws EmailException
 
void sendConfirmIdentityBrokerLink (String link, long expirationInMinutes) throws EmailException
 
void sendExecuteActions (String link, long expirationInMinutes) throws EmailException
 
void sendVerifyEmail (String link, long expirationInMinutes) throws EmailException
 
void send (String subjectFormatKey, String bodyTemplate, Map< String, Object > bodyAttributes) throws EmailException
 
void send (String subjectFormatKey, List< Object > subjectAttributes, String bodyTemplate, Map< String, Object > bodyAttributes) throws EmailException
 
void close ()
 

限定公開メンバ関数

String getRealmName ()
 
void addLinkInfoIntoAttributes (String link, long expirationInMinutes, Map< String, Object > attributes) throws EmailException
 
EmailTemplate processTemplate (String subjectKey, List< Object > subjectAttributes, String template, Map< String, Object > attributes) throws EmailException
 
Theme getTheme () throws IOException
 
void send (String subject, String textBody, String htmlBody) throws EmailException
 
void send (Map< String, String > config, String subject, String textBody, String htmlBody) throws EmailException
 
String toCamelCase (EventType event)
 

限定公開変数類

KeycloakSession session
 
AuthenticationSessionModel authenticationSession
 
FreeMarkerUtil freeMarker
 
RealmModel realm
 
UserModel user
 
final Map< String, Object > attributes = new HashMap<>()
 

詳解

著者
Stian Thorgersen

構築子と解体子

◆ FreeMarkerEmailTemplateProvider()

org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.FreeMarkerEmailTemplateProvider ( KeycloakSession  session,
FreeMarkerUtil  freeMarker 
)
inline
66  {
67  this.session = session;
68  this.freeMarker = freeMarker;
69  }
KeycloakSession session
Definition: FreeMarkerEmailTemplateProvider.java:55
FreeMarkerUtil freeMarker
Definition: FreeMarkerEmailTemplateProvider.java:61

関数詳解

◆ addLinkInfoIntoAttributes()

void org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.addLinkInfoIntoAttributes ( String  link,
long  expirationInMinutes,
Map< String, Object >  attributes 
) throws EmailException
inlineprotected

Add link info into template attributes.

引数
linkto add
expirationInMinutesto add
attributesto add link info into
184  {
185  attributes.put("link", link);
186  attributes.put("linkExpiration", expirationInMinutes);
187  try {
188  Locale locale = session.getContext().resolveLocale(user);
189  attributes.put("linkExpirationFormatter", new LinkExpirationFormatterMethod(getTheme().getMessages(locale), locale));
190  } catch (IOException e) {
191  throw new EmailException("Failed to template email", e);
192  }
193  }
KeycloakSession session
Definition: FreeMarkerEmailTemplateProvider.java:55
UserModel user
Definition: FreeMarkerEmailTemplateProvider.java:63
Theme getTheme()
Definition: FreeMarkerEmailTemplateProvider.java:229
final Map< String, Object > attributes
Definition: FreeMarkerEmailTemplateProvider.java:64

◆ close()

void org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.close ( )
inline
255  {
256  }

◆ getRealmName()

String org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.getRealmName ( )
inlineprotected
95  {
96  if (realm.getDisplayName() != null) {
97  return realm.getDisplayName();
98  } else {
99  return ObjectUtil.capitalize(realm.getName());
100  }
101  }
RealmModel realm
Definition: FreeMarkerEmailTemplateProvider.java:62

◆ getTheme()

Theme org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.getTheme ( ) throws IOException
inlineprotected
229  {
230  return session.theme().getTheme(Theme.Type.EMAIL);
231  }
KeycloakSession session
Definition: FreeMarkerEmailTemplateProvider.java:55

◆ processTemplate()

EmailTemplate org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.processTemplate ( String  subjectKey,
List< Object >  subjectAttributes,
String  template,
Map< String, Object >  attributes 
) throws EmailException
inlineprotected
200  {
201  try {
202  Theme theme = getTheme();
203  Locale locale = session.getContext().resolveLocale(user);
204  attributes.put("locale", locale);
205  Properties rb = theme.getMessages(locale);
206  attributes.put("msg", new MessageFormatterMethod(locale, rb));
207  String subject = new MessageFormat(rb.getProperty(subjectKey, subjectKey), locale).format(subjectAttributes.toArray());
208  String textTemplate = String.format("text/%s", template);
209  String textBody;
210  try {
211  textBody = freeMarker.processTemplate(attributes, textTemplate, theme);
212  } catch (final FreeMarkerException e) {
213  textBody = null;
214  }
215  String htmlTemplate = String.format("html/%s", template);
216  String htmlBody;
217  try {
218  htmlBody = freeMarker.processTemplate(attributes, htmlTemplate, theme);
219  } catch (final FreeMarkerException e) {
220  htmlBody = null;
221  }
222 
223  return new EmailTemplate(subject, textBody, htmlBody);
224  } catch (Exception e) {
225  throw new EmailException("Failed to template email", e);
226  }
227  }
KeycloakSession session
Definition: FreeMarkerEmailTemplateProvider.java:55
FreeMarkerUtil freeMarker
Definition: FreeMarkerEmailTemplateProvider.java:61
UserModel user
Definition: FreeMarkerEmailTemplateProvider.java:63
Theme getTheme()
Definition: FreeMarkerEmailTemplateProvider.java:229
final Map< String, Object > attributes
Definition: FreeMarkerEmailTemplateProvider.java:64
String processTemplate(Object data, String templateName, Theme theme)
Definition: FreeMarkerUtil.java:47

◆ send() [1/4]

void org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.send ( String  subjectFormatKey,
String  bodyTemplate,
Map< String, Object >  bodyAttributes 
) throws EmailException
inline
196  {
197  send(subjectFormatKey, Collections.emptyList(), bodyTemplate, bodyAttributes);
198  }
void send(String subjectFormatKey, String bodyTemplate, Map< String, Object > bodyAttributes)
Definition: FreeMarkerEmailTemplateProvider.java:196

◆ send() [2/4]

void org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.send ( String  subjectFormatKey,
List< Object >  subjectAttributes,
String  bodyTemplate,
Map< String, Object >  bodyAttributes 
) throws EmailException
inline
234  {
235  try {
236  EmailTemplate email = processTemplate(subjectFormatKey, subjectAttributes, bodyTemplate, bodyAttributes);
237  send(email.getSubject(), email.getTextBody(), email.getHtmlBody());
238  } catch (EmailException e) {
239  throw e;
240  } catch (Exception e) {
241  throw new EmailException("Failed to template email", e);
242  }
243  }
void send(String subjectFormatKey, String bodyTemplate, Map< String, Object > bodyAttributes)
Definition: FreeMarkerEmailTemplateProvider.java:196
EmailTemplate processTemplate(String subjectKey, List< Object > subjectAttributes, String template, Map< String, Object > attributes)
Definition: FreeMarkerEmailTemplateProvider.java:200

◆ send() [3/4]

void org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.send ( String  subject,
String  textBody,
String  htmlBody 
) throws EmailException
inlineprotected
245  {
246  send(realm.getSmtpConfig(), subject, textBody, htmlBody);
247  }
void send(String subjectFormatKey, String bodyTemplate, Map< String, Object > bodyAttributes)
Definition: FreeMarkerEmailTemplateProvider.java:196
RealmModel realm
Definition: FreeMarkerEmailTemplateProvider.java:62

◆ send() [4/4]

void org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.send ( Map< String, String >  config,
String  subject,
String  textBody,
String  htmlBody 
) throws EmailException
inlineprotected
249  {
250  EmailSenderProvider emailSender = session.getProvider(EmailSenderProvider.class);
251  emailSender.send(config, user, subject, textBody, htmlBody);
252  }
KeycloakSession session
Definition: FreeMarkerEmailTemplateProvider.java:55
UserModel user
Definition: FreeMarkerEmailTemplateProvider.java:63

◆ sendConfirmIdentityBrokerLink()

void org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.sendConfirmIdentityBrokerLink ( String  link,
long  expirationInMinutes 
) throws EmailException
inline
137  {
138  Map<String, Object> attributes = new HashMap<String, Object>(this.attributes);
139  attributes.put("user", new ProfileBean(user));
140  addLinkInfoIntoAttributes(link, expirationInMinutes, attributes);
141 
142  attributes.put("realmName", getRealmName());
143 
144  BrokeredIdentityContext brokerContext = (BrokeredIdentityContext) this.attributes.get(IDENTITY_PROVIDER_BROKER_CONTEXT);
145  String idpAlias = brokerContext.getIdpConfig().getAlias();
146  idpAlias = ObjectUtil.capitalize(idpAlias);
147 
148  attributes.put("identityProviderContext", brokerContext);
149  attributes.put("identityProviderAlias", idpAlias);
150 
151  List<Object> subjectAttrs = Arrays.<Object> asList(idpAlias);
152  send("identityProviderLinkSubject", subjectAttrs, "identity-provider-link.ftl", attributes);
153  }
void send(String subjectFormatKey, String bodyTemplate, Map< String, Object > bodyAttributes)
Definition: FreeMarkerEmailTemplateProvider.java:196
UserModel user
Definition: FreeMarkerEmailTemplateProvider.java:63
String getRealmName()
Definition: FreeMarkerEmailTemplateProvider.java:95
final Map< String, Object > attributes
Definition: FreeMarkerEmailTemplateProvider.java:64
void addLinkInfoIntoAttributes(String link, long expirationInMinutes, Map< String, Object > attributes)
Definition: FreeMarkerEmailTemplateProvider.java:184

◆ sendEvent()

void org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.sendEvent ( Event  event) throws EmailException
inline
104  {
105  Map<String, Object> attributes = new HashMap<String, Object>();
106  attributes.put("user", new ProfileBean(user));
107  attributes.put("event", new EventBean(event));
108 
109  send(toCamelCase(event.getType()) + "Subject", "event-" + event.getType().toString().toLowerCase() + ".ftl", attributes);
110  }
void send(String subjectFormatKey, String bodyTemplate, Map< String, Object > bodyAttributes)
Definition: FreeMarkerEmailTemplateProvider.java:196
UserModel user
Definition: FreeMarkerEmailTemplateProvider.java:63
final Map< String, Object > attributes
Definition: FreeMarkerEmailTemplateProvider.java:64
String toCamelCase(EventType event)
Definition: FreeMarkerEmailTemplateProvider.java:258

◆ sendExecuteActions()

void org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.sendExecuteActions ( String  link,
long  expirationInMinutes 
) throws EmailException
inline
156  {
157  Map<String, Object> attributes = new HashMap<String, Object>(this.attributes);
158  attributes.put("user", new ProfileBean(user));
159  addLinkInfoIntoAttributes(link, expirationInMinutes, attributes);
160 
161  attributes.put("realmName", getRealmName());
162 
163  send("executeActionsSubject", "executeActions.ftl", attributes);
164  }
void send(String subjectFormatKey, String bodyTemplate, Map< String, Object > bodyAttributes)
Definition: FreeMarkerEmailTemplateProvider.java:196
UserModel user
Definition: FreeMarkerEmailTemplateProvider.java:63
String getRealmName()
Definition: FreeMarkerEmailTemplateProvider.java:95
final Map< String, Object > attributes
Definition: FreeMarkerEmailTemplateProvider.java:64
void addLinkInfoIntoAttributes(String link, long expirationInMinutes, Map< String, Object > attributes)
Definition: FreeMarkerEmailTemplateProvider.java:184

◆ sendPasswordReset()

void org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.sendPasswordReset ( String  link,
long  expirationInMinutes 
) throws EmailException
inline
113  {
114  Map<String, Object> attributes = new HashMap<String, Object>(this.attributes);
115  attributes.put("user", new ProfileBean(user));
116  addLinkInfoIntoAttributes(link, expirationInMinutes, attributes);
117 
118  attributes.put("realmName", getRealmName());
119 
120  send("passwordResetSubject", "password-reset.ftl", attributes);
121  }
void send(String subjectFormatKey, String bodyTemplate, Map< String, Object > bodyAttributes)
Definition: FreeMarkerEmailTemplateProvider.java:196
UserModel user
Definition: FreeMarkerEmailTemplateProvider.java:63
String getRealmName()
Definition: FreeMarkerEmailTemplateProvider.java:95
final Map< String, Object > attributes
Definition: FreeMarkerEmailTemplateProvider.java:64
void addLinkInfoIntoAttributes(String link, long expirationInMinutes, Map< String, Object > attributes)
Definition: FreeMarkerEmailTemplateProvider.java:184

◆ sendSmtpTestEmail()

void org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.sendSmtpTestEmail ( Map< String, String >  config,
UserModel  user 
) throws EmailException
inline
124  {
125  setRealm(session.getContext().getRealm());
126  setUser(user);
127 
128  Map<String, Object> attributes = new HashMap<String, Object>(this.attributes);
129  attributes.put("user", new ProfileBean(user));
130  attributes.put("realmName", realm.getName());
131 
132  EmailTemplate email = processTemplate("emailTestSubject", Collections.emptyList(), "email-test.ftl", attributes);
133  send(config, email.getSubject(), email.getTextBody(), email.getHtmlBody());
134  }
KeycloakSession session
Definition: FreeMarkerEmailTemplateProvider.java:55
void send(String subjectFormatKey, String bodyTemplate, Map< String, Object > bodyAttributes)
Definition: FreeMarkerEmailTemplateProvider.java:196
UserModel user
Definition: FreeMarkerEmailTemplateProvider.java:63
EmailTemplate processTemplate(String subjectKey, List< Object > subjectAttributes, String template, Map< String, Object > attributes)
Definition: FreeMarkerEmailTemplateProvider.java:200
final Map< String, Object > attributes
Definition: FreeMarkerEmailTemplateProvider.java:64
EmailTemplateProvider setUser(UserModel user)
Definition: FreeMarkerEmailTemplateProvider.java:78
RealmModel realm
Definition: FreeMarkerEmailTemplateProvider.java:62
EmailTemplateProvider setRealm(RealmModel realm)
Definition: FreeMarkerEmailTemplateProvider.java:72

◆ sendVerifyEmail()

void org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.sendVerifyEmail ( String  link,
long  expirationInMinutes 
) throws EmailException
inline
167  {
168  Map<String, Object> attributes = new HashMap<String, Object>(this.attributes);
169  attributes.put("user", new ProfileBean(user));
170  addLinkInfoIntoAttributes(link, expirationInMinutes, attributes);
171 
172  attributes.put("realmName", getRealmName());
173 
174  send("emailVerificationSubject", "email-verification.ftl", attributes);
175  }
void send(String subjectFormatKey, String bodyTemplate, Map< String, Object > bodyAttributes)
Definition: FreeMarkerEmailTemplateProvider.java:196
UserModel user
Definition: FreeMarkerEmailTemplateProvider.java:63
String getRealmName()
Definition: FreeMarkerEmailTemplateProvider.java:95
final Map< String, Object > attributes
Definition: FreeMarkerEmailTemplateProvider.java:64
void addLinkInfoIntoAttributes(String link, long expirationInMinutes, Map< String, Object > attributes)
Definition: FreeMarkerEmailTemplateProvider.java:184

◆ setAttribute()

EmailTemplateProvider org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.setAttribute ( String  name,
Object  value 
)
inline
84  {
85  attributes.put(name, value);
86  return this;
87  }
final Map< String, Object > attributes
Definition: FreeMarkerEmailTemplateProvider.java:64

◆ setAuthenticationSession()

EmailTemplateProvider org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.setAuthenticationSession ( AuthenticationSessionModel  authenticationSession)
inline
90  {
92  return this;
93  }
AuthenticationSessionModel authenticationSession
Definition: FreeMarkerEmailTemplateProvider.java:60

◆ setRealm()

EmailTemplateProvider org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.setRealm ( RealmModel  realm)
inline
72  {
73  this.realm = realm;
74  return this;
75  }
RealmModel realm
Definition: FreeMarkerEmailTemplateProvider.java:62

◆ setUser()

EmailTemplateProvider org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.setUser ( UserModel  user)
inline
78  {
79  this.user = user;
80  return this;
81  }
UserModel user
Definition: FreeMarkerEmailTemplateProvider.java:63

◆ toCamelCase()

String org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.toCamelCase ( EventType  event)
inlineprotected
258  {
259  StringBuilder sb = new StringBuilder("event");
260  for (String s : event.name().toLowerCase().split("_")) {
261  sb.append(ObjectUtil.capitalize(s));
262  }
263  return sb.toString();
264  }

メンバ詳解

◆ attributes

final Map<String, Object> org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.attributes = new HashMap<>()
protected

◆ authenticationSession

AuthenticationSessionModel org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.authenticationSession
protected

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

FreeMarkerUtil org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.freeMarker
protected

◆ realm

RealmModel org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.realm
protected

◆ session

KeycloakSession org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.session
protected

◆ user

UserModel org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.user
protected

このクラス詳解は次のファイルから抽出されました: