Search in sources :

Example 1 with MessageBean

use of org.keycloak.theme.beans.MessageBean in project keycloak by keycloak.

the class FreeMarkerLoginFormsProvider method handleMessages.

/**
 * Handle messages to be shown on the page - set them to template attributes
 *
 * @param locale to be used for message text loading
 * @param messagesBundle to be used for message text loading
 * @see #messageType
 * @see #messages
 */
protected void handleMessages(Locale locale, Properties messagesBundle) {
    MessagesPerFieldBean messagesPerField = new MessagesPerFieldBean();
    if (messages != null) {
        MessageBean wholeMessage = new MessageBean(null, messageType);
        for (FormMessage message : this.messages) {
            String formattedMessageText = formatMessage(message, messagesBundle, locale);
            if (formattedMessageText != null) {
                wholeMessage.appendSummaryLine(formattedMessageText);
                messagesPerField.addMessage(message.getField(), formattedMessageText, messageType);
            }
        }
        attributes.put("message", wholeMessage);
    } else {
        attributes.put("message", null);
    }
    attributes.put("messagesPerField", messagesPerField);
}
Also used : MessageBean(org.keycloak.theme.beans.MessageBean) MessagesPerFieldBean(org.keycloak.theme.beans.MessagesPerFieldBean) FormMessage(org.keycloak.models.utils.FormMessage)

Example 2 with MessageBean

use of org.keycloak.theme.beans.MessageBean in project keycloak by keycloak.

the class FreeMarkerAccountProvider method handleMessages.

/**
 * Handle messages to be shown on the page - set them to template attributes
 *
 * @param locale to be used for message text loading
 * @param messagesBundle to be used for message text loading
 * @param attributes template attributes to messages related info to
 * @see #messageType
 * @see #messages
 */
protected void handleMessages(Locale locale, Properties messagesBundle, Map<String, Object> attributes) {
    MessagesPerFieldBean messagesPerField = new MessagesPerFieldBean();
    if (messages != null) {
        MessageBean wholeMessage = new MessageBean(null, messageType);
        for (FormMessage message : this.messages) {
            String formattedMessageText = formatMessage(message, messagesBundle, locale);
            if (formattedMessageText != null) {
                wholeMessage.appendSummaryLine(formattedMessageText);
                messagesPerField.addMessage(message.getField(), formattedMessageText, messageType);
            }
        }
        attributes.put("message", wholeMessage);
    }
    attributes.put("messagesPerField", messagesPerField);
}
Also used : MessageBean(org.keycloak.theme.beans.MessageBean) MessagesPerFieldBean(org.keycloak.theme.beans.MessagesPerFieldBean) FormMessage(org.keycloak.models.utils.FormMessage)

Example 3 with MessageBean

use of org.keycloak.theme.beans.MessageBean in project keycloak by keycloak.

the class KeycloakErrorHandler method initAttributes.

private Map<String, Object> initAttributes(KeycloakSession session, RealmModel realm, Theme theme, Locale locale, int statusCode) throws IOException {
    Map<String, Object> attributes = new HashMap<>();
    Properties messagesBundle = theme.getMessages(locale);
    attributes.put("statusCode", statusCode);
    attributes.put("realm", realm);
    attributes.put("url", new UrlBean(realm, theme, session.getContext().getUri().getBaseUri(), null));
    attributes.put("locale", new LocaleBean(realm, locale, session.getContext().getUri().getBaseUriBuilder(), messagesBundle));
    String errorKey = statusCode == 404 ? Messages.PAGE_NOT_FOUND : Messages.INTERNAL_SERVER_ERROR;
    String errorMessage = messagesBundle.getProperty(errorKey);
    attributes.put("message", new MessageBean(errorMessage, MessageType.ERROR));
    try {
        attributes.put("msg", new MessageFormatterMethod(locale, theme.getMessages(locale)));
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        attributes.put("properties", theme.getProperties());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return attributes;
}
Also used : MessageBean(org.keycloak.theme.beans.MessageBean) UrlBean(org.keycloak.forms.login.freemarker.model.UrlBean) HashMap(java.util.HashMap) IOException(java.io.IOException) Properties(java.util.Properties) MessageFormatterMethod(org.keycloak.theme.beans.MessageFormatterMethod) LocaleBean(org.keycloak.theme.beans.LocaleBean)

Aggregations

MessageBean (org.keycloak.theme.beans.MessageBean)3 FormMessage (org.keycloak.models.utils.FormMessage)2 MessagesPerFieldBean (org.keycloak.theme.beans.MessagesPerFieldBean)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 UrlBean (org.keycloak.forms.login.freemarker.model.UrlBean)1 LocaleBean (org.keycloak.theme.beans.LocaleBean)1 MessageFormatterMethod (org.keycloak.theme.beans.MessageFormatterMethod)1