[keycloak-user] Unable to get first and last name of newly created user during register event

Danny Im imxxx021 at umn.edu
Fri Aug 18 17:11:15 EDT 2017


Hi,

I created a class implementing the EventListenerProvider interface, and on
the 'register' event, when I retrieve the newly created user, both the
first and last name are set to null.  The newly created user has their
first and last name set later on, but I was wondering if it was possible to
get that information during the 'register' event.

public class MyListenerProvider implements EventListenerProvider {

    private KeycloakSession session;

    public MyListenerProvider(KeycloakSession session) {
        this.session = session;
    }
    public void onEvent(Event event) {
        EventType eventType = event.getType();
        if(eventType.equals(EventType.REGISTER)) {
            String realmId = event.getRealmId();
            String userId = event.getUserId();
            RealmModel realm = session.getContext().getRealm();
            UserModel user = session.users().getUserById(userId, realm);
            String username = user.getUsername();
            // the following are null for newly created users
            String firstName = user.getFirstName();
            String lastName = user.getLastName();
        }
    }
    public void onEvent(AdminEvent event, boolean includeRepresentation) {
    }
    public void close() {
    }
}


Thanks!

-- 
Danny Im
Software Developer
Polar Geospatial Center
University of Minnesota


More information about the keycloak-user mailing list