From 30ea556a7a12f94a52683e3a067c5e8ac090a1da Mon Sep 17 00:00:00 2001 From: John Ament Date: Fri, 25 Aug 2017 01:30:26 -0400 Subject: [PATCH] KEYCLOAK-5285: Adding protected access. (#4405) Allows FreemarkerEmailTemplateProvider to be more extensible. --- .../FreeMarkerEmailTemplateProvider.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/services/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailTemplateProvider.java b/services/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailTemplateProvider.java index ddf29a15aa..09a3789e98 100755 --- a/services/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailTemplateProvider.java +++ b/services/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailTemplateProvider.java @@ -49,11 +49,11 @@ import java.util.Properties; */ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider { - private KeycloakSession session; - private FreeMarkerUtil freeMarker; - private RealmModel realm; - private UserModel user; - private final Map attributes = new HashMap<>(); + protected KeycloakSession session; + protected FreeMarkerUtil freeMarker; + protected RealmModel realm; + protected UserModel user; + protected final Map attributes = new HashMap<>(); public FreeMarkerEmailTemplateProvider(KeycloakSession session, FreeMarkerUtil freeMarker) { this.session = session; @@ -78,7 +78,7 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider { return this; } - private String getRealmName() { + protected String getRealmName() { if (realm.getDisplayName() != null) { return realm.getDisplayName(); } else { @@ -165,11 +165,11 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider { send("emailVerificationSubject", "email-verification.ftl", attributes); } - private void send(String subjectKey, String template, Map attributes) throws EmailException { + protected void send(String subjectKey, String template, Map attributes) throws EmailException { send(subjectKey, Collections.emptyList(), template, attributes); } - private EmailTemplate processTemplate(String subjectKey, List subjectAttributes, String template, Map attributes) throws EmailException { + protected EmailTemplate processTemplate(String subjectKey, List subjectAttributes, String template, Map attributes) throws EmailException { try { ThemeProvider themeProvider = session.getProvider(ThemeProvider.class, "extending"); Theme theme = themeProvider.getTheme(realm.getEmailTheme(), Theme.Type.EMAIL); @@ -198,7 +198,7 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider { throw new EmailException("Failed to template email", e); } } - private void send(String subjectKey, List subjectAttributes, String template, Map attributes) throws EmailException { + protected void send(String subjectKey, List subjectAttributes, String template, Map attributes) throws EmailException { try { EmailTemplate email = processTemplate(subjectKey, subjectAttributes, template, attributes); send(email.getSubject(), email.getTextBody(), email.getHtmlBody()); @@ -207,11 +207,11 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider { } } - private void send(String subject, String textBody, String htmlBody) throws EmailException { + protected void send(String subject, String textBody, String htmlBody) throws EmailException { send(realm.getSmtpConfig(), subject, textBody, htmlBody); } - private void send(Map config, String subject, String textBody, String htmlBody) throws EmailException { + protected void send(Map config, String subject, String textBody, String htmlBody) throws EmailException { EmailSenderProvider emailSender = session.getProvider(EmailSenderProvider.class); emailSender.send(config, user, subject, textBody, htmlBody); } @@ -220,15 +220,15 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider { public void close() { } - private String toCamelCase(EventType event){ + protected String toCamelCase(EventType event){ StringBuilder sb = new StringBuilder("event"); - for(String s : event.name().toString().toLowerCase().split("_")){ + for(String s : event.name().toLowerCase().split("_")){ sb.append(ObjectUtil.capitalize(s)); } return sb.toString(); } - private class EmailTemplate { + protected class EmailTemplate { private String subject; private String textBody;