[keycloak-user] REGISTER event: firstName & lastName always NULL

Thilo Frotscher keycloak at frotscher.com
Tue Jan 9 05:01:28 EST 2018


Hi all,

In our project there is a requirement to execute some actions after successful
user registrations. I implemented an EventListenerProvider that listens to events
of type REGISTER. The details of this event type only contain the "username" of
the user that just registered, but first name and last name are missing.

So I thought I could retrieve this information from the user storage. But no
matter how I try to read the user information from the user storage, firstName
and lastName are always null.

Is this a bug or a feature? When manually logging on to the Admin Console,
I can see that firstName and lastName have been correctly saved. But how
can I programmatically retrieve the first name and last name of the user
that just registered in my event listener?

Sample code:

    public void onEvent(Event event) {

        if (!EventType.REGISTER.equals(event.getType())) {
            LOGGER.info("Ignoring event of type " + event.getType());
            return;
        }

        String realmId = event.getRealmId();
        RealmModel realm = session.realms().getRealm(realmId);

        String userId = event.getUserId();

        Map<String, String> details = event.getDetails();
        String username = details.get("username");

        printUser(session.users().getUserByUsername(username, realm));
        printUser(session.userLocalStorage().getUserByUsername(username, realm));
        printUser(session.userCache().getUserByUsername(username, realm));
        printUser(session.userStorageManager().getUserByUsername(username, realm));

    }

    private void printUser(UserModel user) {
        if (user==null) {
            LOGGER.info("User is null");
        } else {
            LOGGER.info(user.getFirstName()); // always null
            LOGGER.info(user.getLastName()); // always null
            LOGGER.info(user.getId());
            LOGGER.info(user.getEmail());
            LOGGER.info(user.getUsername());
        }
    }

Actually, I believe firstName and lastName should be part of the event details
in the first place...

Thanks for your help!

Cheers,
Thilo


More information about the keycloak-user mailing list