KEYCLOAK-5285: Adding protected access. (#4405)
Allows FreemarkerEmailTemplateProvider to be more extensible.
This commit is contained in:
parent
5484e088aa
commit
30ea556a7a
1 changed files with 14 additions and 14 deletions
|
@ -49,11 +49,11 @@ import java.util.Properties;
|
||||||
*/
|
*/
|
||||||
public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider {
|
public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider {
|
||||||
|
|
||||||
private KeycloakSession session;
|
protected KeycloakSession session;
|
||||||
private FreeMarkerUtil freeMarker;
|
protected FreeMarkerUtil freeMarker;
|
||||||
private RealmModel realm;
|
protected RealmModel realm;
|
||||||
private UserModel user;
|
protected UserModel user;
|
||||||
private final Map<String, Object> attributes = new HashMap<>();
|
protected final Map<String, Object> attributes = new HashMap<>();
|
||||||
|
|
||||||
public FreeMarkerEmailTemplateProvider(KeycloakSession session, FreeMarkerUtil freeMarker) {
|
public FreeMarkerEmailTemplateProvider(KeycloakSession session, FreeMarkerUtil freeMarker) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
|
@ -78,7 +78,7 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRealmName() {
|
protected String getRealmName() {
|
||||||
if (realm.getDisplayName() != null) {
|
if (realm.getDisplayName() != null) {
|
||||||
return realm.getDisplayName();
|
return realm.getDisplayName();
|
||||||
} else {
|
} else {
|
||||||
|
@ -165,11 +165,11 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider {
|
||||||
send("emailVerificationSubject", "email-verification.ftl", attributes);
|
send("emailVerificationSubject", "email-verification.ftl", attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void send(String subjectKey, String template, Map<String, Object> attributes) throws EmailException {
|
protected void send(String subjectKey, String template, Map<String, Object> attributes) throws EmailException {
|
||||||
send(subjectKey, Collections.emptyList(), template, attributes);
|
send(subjectKey, Collections.emptyList(), template, attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private EmailTemplate processTemplate(String subjectKey, List<Object> subjectAttributes, String template, Map<String, Object> attributes) throws EmailException {
|
protected EmailTemplate processTemplate(String subjectKey, List<Object> subjectAttributes, String template, Map<String, Object> attributes) throws EmailException {
|
||||||
try {
|
try {
|
||||||
ThemeProvider themeProvider = session.getProvider(ThemeProvider.class, "extending");
|
ThemeProvider themeProvider = session.getProvider(ThemeProvider.class, "extending");
|
||||||
Theme theme = themeProvider.getTheme(realm.getEmailTheme(), Theme.Type.EMAIL);
|
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);
|
throw new EmailException("Failed to template email", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void send(String subjectKey, List<Object> subjectAttributes, String template, Map<String, Object> attributes) throws EmailException {
|
protected void send(String subjectKey, List<Object> subjectAttributes, String template, Map<String, Object> attributes) throws EmailException {
|
||||||
try {
|
try {
|
||||||
EmailTemplate email = processTemplate(subjectKey, subjectAttributes, template, attributes);
|
EmailTemplate email = processTemplate(subjectKey, subjectAttributes, template, attributes);
|
||||||
send(email.getSubject(), email.getTextBody(), email.getHtmlBody());
|
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);
|
send(realm.getSmtpConfig(), subject, textBody, htmlBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void send(Map<String, String> config, String subject, String textBody, String htmlBody) throws EmailException {
|
protected void send(Map<String, String> config, String subject, String textBody, String htmlBody) throws EmailException {
|
||||||
EmailSenderProvider emailSender = session.getProvider(EmailSenderProvider.class);
|
EmailSenderProvider emailSender = session.getProvider(EmailSenderProvider.class);
|
||||||
emailSender.send(config, user, subject, textBody, htmlBody);
|
emailSender.send(config, user, subject, textBody, htmlBody);
|
||||||
}
|
}
|
||||||
|
@ -220,15 +220,15 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider {
|
||||||
public void close() {
|
public void close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String toCamelCase(EventType event){
|
protected String toCamelCase(EventType event){
|
||||||
StringBuilder sb = new StringBuilder("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));
|
sb.append(ObjectUtil.capitalize(s));
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EmailTemplate {
|
protected class EmailTemplate {
|
||||||
|
|
||||||
private String subject;
|
private String subject;
|
||||||
private String textBody;
|
private String textBody;
|
||||||
|
|
Loading…
Reference in a new issue