简体   繁体   中英

Keycloak custom Event Listener SPI: UPDATE_PROFILE event details returns null for changes to custom attributes

I am working on a custom Event Listener SPI for Keycloak. The event listener works; however, I am having issues with getting the details of the UPDATE_PROFILE event type. When using event.getDetails() which should return a Map of the details of the event, it instead returns null .

I am trying to get the details of what fields were updated by the user, their old values, and their new values for auditing purposes.

The code I currently have for trying to log the event details is the following:

logger.info("Got an event of type: {}", event.getType());
logger.info("Event details:");
if (event.getDetails() != null) {
   for (String key : event.getDetails().keySet()) {
      logger.info("Key: {}, Value: {}", key, event.getDetails().get(key));
   }
}

...

switch (event.getType()) {
    case UPDATE_PROFILE:
        logger.info("User updated his/her profile");
        logger.info("UPDATE_PROFILE event details: {}", event.getDetails());
        break;

With the above code, after updating the profile, the logs show this:
Keycloak 事件监听器日志输出

EDIT: It logs changes only to fields that existed in the base Keycloak theme (email, first name, and last name). Any changes to any of the custom fields we added to our custom theme is when the event details are null and it does not log anything.

Any help is greatly appreciated.

I am providing this as an answer to my issue for anyone else who may be running into this issue.

The issue I was running into was documented as an enhancement here . I was running Keycloak v15.0.2 when I experienced this issue. This has since been fixed in the latest version of Keycloak, v16.1.0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM