Search

Dark theme | Light theme
Showing posts with label Keycloak. Show all posts
Showing posts with label Keycloak. Show all posts

November 23, 2022

Change Log Level For Events In Keycloak

When running Keycloak it can be useful to log events like a login or logout event using the jboss-logging event listener. This is a built-in event listener that will use JBoss logging to log events. For example we can configure our JBoss logging to log to the standard output streams and when we run Keycloak we can see in the console output details about events when they happen. The event listener jboss-logging is enabled by default for a realm. We can check it from the Events Config page where it is listed in the Event Listeners field.

By default the log level of error events is set to warn and for successful events to log level debug. If we want to change the log level we can use two configuration properties to achieve this:

  • spi-events-listener-jboss-logging-success-level to set the log level for events that are a success. The default value is debug, but we can change it to for example info. Valid values for the log levels are fatal, error, warn, info, debug and trace.
  • spi-events-listener-jboss-logging-error-level to set the log level for events that went wrong. The default value is warn. We can any of the valid log level values here as well.

To pass the configuration property with a value to Keycloak we can use the command-line version where we for prefix the property with two dashes (--). For example:

$ kc.sh start \
 --spi-events-listener-jboss-logging-success-level=info \
 --spi-events-listener-jboss-logging-error-level=error

Or we can use the environment variables KC_SPI_EVENTS_LISTENER_JBOSS_LOGGING_SUCCESS_LEVEL and KC_SPI_EVENTS_LISTENER_JBOSS_LOGGING_ERROR_LEVEL and given them the correct log level values. In the following example we use the environment variables:

$ KC_SPI_EVENTS_LISTENER_JBOSS_LOGGING_SUCCESS_LEVEL=info \
 KC_SPI_EVENTS_LISTENER_JBOSS_LOGGING_ERROR_LEVEL=error \
 kc.sh start

Written with Keycloak 18.0.2.

October 16, 2020

Enforce Encoding i18n Property Files In Keycloak Themes

Keycloak allows internationalization messages in themes. We can specify property files with messages for a specific locale. The fallback locale is always en, so we need at least the file messsages_en.properties. To use the messages from the property files we use the msg function in our Freemarker templates. We specify the message key as argument to this function and the corresponding value will be shown to the user. This function is added by Keycloak and reads the property files, finds the key and returns the value. Keycloak uses as default encoding for reading the property files ISO-8859-1. This gives issues when we use non-compliant characters in our property file, like letters with accents. We can force Keycloak to use anonther encoding by adding an extra line to our property files at the top with the encoding we want to be used. The line starts with a #, so it is a comment, followed by the text encoding: and the encoding we want, e.g. UTF-8.

In the following example we set the encoding to UTF-8 as first line in the property file, and we must make sure the file is also saved with the same encoding:

# encoding: UTF-8 
doSave=Mentés
doCancel=Mégsem
...

In the following Freemaker template we use the msg function to get the key doSave:

...
<button name="submitAction" value="Save">${msg("doSave")}<button>
...

Written with Keycloak 11.0.2.