KEYCLOAK-9837 Not hide exception in email templating
This commit is contained in:
parent
530b99c933
commit
476da4f276
2 changed files with 12 additions and 0 deletions
|
@ -26,6 +26,10 @@ public class EmailException extends Exception {
|
|||
super(cause);
|
||||
}
|
||||
|
||||
public EmailException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public EmailException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.broker.provider.BrokeredIdentityContext;
|
||||
import org.keycloak.common.util.ObjectUtil;
|
||||
import org.keycloak.email.EmailException;
|
||||
|
@ -54,6 +55,7 @@ import org.keycloak.theme.beans.MessageFormatterMethod;
|
|||
*/
|
||||
public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(FreeMarkerEmailTemplateProvider.class);
|
||||
protected KeycloakSession session;
|
||||
/**
|
||||
* 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
|
||||
|
@ -217,6 +219,7 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider {
|
|||
textBody = freeMarker.processTemplate(attributes, textTemplate, theme);
|
||||
} catch (final FreeMarkerException e) {
|
||||
textBody = null;
|
||||
logger.warn("Failed to template plain text email.", e);
|
||||
}
|
||||
String htmlTemplate = String.format("html/%s", template);
|
||||
String htmlBody;
|
||||
|
@ -224,6 +227,11 @@ public class FreeMarkerEmailTemplateProvider implements EmailTemplateProvider {
|
|||
htmlBody = freeMarker.processTemplate(attributes, htmlTemplate, theme);
|
||||
} catch (final FreeMarkerException e) {
|
||||
htmlBody = null;
|
||||
logger.warn("Failed to template html email.", e);
|
||||
}
|
||||
|
||||
if (textBody == null && htmlBody == null) {
|
||||
throw new EmailException("Both plain text and html are empty!");
|
||||
}
|
||||
|
||||
return new EmailTemplate(subject, textBody, htmlBody);
|
||||
|
|
Loading…
Reference in a new issue