Passing data from authenticator to event listener

Keycloak 20.0.5.

I have a custom authentificator in my flow, that attempts to set some variables that are to be picked later by an event listener (in real life they will not be constant of course).

This is in my authenticator:

    @Override
public void authenticate(AuthenticationFlowContext context) {
    log.info("Authenticate called...");
    
    //MultivaluedMap<String, String> formData = context.getHttpRequest().getDecodedFormParameters();
    
    context.getHttpRequest().getHttpHeaders().getCookies().forEach((key, value) -> log.debugf("kolacik %s : %s",key, value.getValue()));

    KeycloakSession session = context.getSession();

    //RealmModel realm = context.getRealm();
    
    log.info("Setting attribute attr");    
    session.setAttribute("attr", "9");
    log.info(session.getAttribute("attr"));
    
    log.info("Setting AuthNote");
    context.getAuthenticationSession().setAuthNote("auth_note", "8");
    log.info(context.getAuthenticationSession().getAuthNote("auth_note"));
    
    log.info("Setting UserSessionNote");
    context.getAuthenticationSession().setUserSessionNote("sess_note", "7");
    log.info(context.getAuthenticationSession().getUserSessionNotes().get("sess_note"));
    
    context.success();
}

This is in my event listener:

@Override
public void onEvent(Event event) {

    log.debugf("New %s Event", event.getType());
    log.debugf("onEvent-> %s", toString(event));
    
    
    log.debug("Printing event details");
    event.getDetails().forEach((key, value) -> log.debugf("event attribute %s : %s",key, value));
    
    log.debug("Printing session details");
    Object a = session.getAttribute("attr");
    if (a != null) {
        log.debugf("session: ", a.toString());
    }
    
    log.debug("Printing auth note");
    String an = session.getContext().getAuthenticationSession().getAuthNote("auth_note");
    log.debugf("auth_note: ", an);
    
    log.debug("Print user session note");
    String sn = session.getContext().getAuthenticationSession().getUserSessionNotes().get("sess_note");
    log.debugf("sess_note: ", sn);
    
    log.debug("Printing user details");
    RealmModel realm = this.model.getRealm(event.getRealmId());
    UserModel user = this.session.users().getUserById(realm, event.getUserId());
    
    if (user != null && user.getAttributes() != null && !user.getAttributes().isEmpty()) {
        user.getAttributes().forEach((key, value) -> log.debugf("user detail %s : %s",key, value));
    }
}

The problem is, I can see that the values are set in authenticator, but in listener they are null/not available.

2024-01-29 15:03:02,850 INFO  [codelens.authenticators.CustomSetSessionVariable] (executor-thread-5) Authenticate called...
2024-01-29 15:03:02,851 DEBUG [codelens.authenticators.CustomSetSessionVariable] (executor-thread-5) kolacik AUTH_SESSION_ID_LEGACY : 204ec99d-a1f5-45e8-98c0-c731b9608033
2024-01-29 15:03:02,851 DEBUG [codelens.authenticators.CustomSetSessionVariable] (executor-thread-5) kolacik KC_RESTART : eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJlODcwYjU4ZC02NDNjLTQ0MzQtYTEzOC0wZmFkM2RiY2ZkZDgifQ.eyJjaWQiOiJteS1hcGV4LWFwcGxpY2F0aW9uIiwicHR5Ijoib3BlbmlkLWNvbm5lY3QiLCJydXJpIjoiaHR0cHM6Ly9nY2ZiM2E1ODM3Yjc0ZDctams2dzN0OWRxd2h4bDgxZS5hZGIuZXUtbWlsYW4tMS5vcmFjbGVjbG91ZGFwcHMuY29tL29yZHMvYXBleF9hdXRoZW50aWNhdGlvbi5jYWxsYmFjayIsImFjdCI6IkFVVEhFTlRJQ0FURSIsIm5vdGVzIjp7InNjb3BlIjoib3BlbmlkIGVtYWlsIHByb2ZpbGUiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvcmVhbG1zL2FwcGxpY2F0aW9uIiwicmVzcG9uc2VfdHlwZSI6ImNvZGUiLCJyZWRpcmVjdF91cmkiOiJodHRwczovL2djZmIzYTU4MzdiNzRkNy1qazZ3M3Q5ZHF3aHhsODFlLmFkYi5ldS1taWxhbi0xLm9yYWNsZWNsb3VkYXBwcy5jb20vb3Jkcy9hcGV4X2F1dGhlbnRpY2F0aW9uLmNhbGxiYWNrIiwic3RhdGUiOiJQT2s0bFhaTkd3RXFrbzFyOGs1a1VNTUhFQzVlYmFvbEg3RjJPb1dQcnRhS2dfMHlrMzlqQ1hkNVhNUzhEdDc4eHVVeUQ4ZExfQ29yeUs4ajhFaG1YWGRRdDhpSHlTTXpaaDkwRUJuRncxaEtPMC1UZUJnT0JWLVBQT18xOGRUYnRXdVFVdnRacUtoY2NjdEpWWnl1Y2pOSDdudmhhN2E5N0VQU0ozY0NaUWNkTzdZVnlZV1dieWlubGNaVWszZE1mWHRheGQyS0pyM0hxbmtDQWNkRFR3In19.dw6hDuDBGZKFD7GGPzkGqXM2zH7ws60M_wZ8g9Ijyjo
2024-01-29 15:03:02,851 DEBUG [codelens.authenticators.CustomSetSessionVariable] (executor-thread-5) kolacik AUTH_SESSION_ID : 204ec99d-a1f5-45e8-98c0-c731b9608033
2024-01-29 15:03:02,852 INFO  [codelens.authenticators.CustomSetSessionVariable] (executor-thread-5) Setting attribute attr
2024-01-29 15:03:02,852 INFO  [codelens.authenticators.CustomSetSessionVariable] (executor-thread-5) 9
2024-01-29 15:03:02,852 INFO  [codelens.authenticators.CustomSetSessionVariable] (executor-thread-5) Setting AuthNote
2024-01-29 15:03:02,852 INFO  [codelens.authenticators.CustomSetSessionVariable] (executor-thread-5) 8
2024-01-29 15:03:02,852 INFO  [codelens.authenticators.CustomSetSessionVariable] (executor-thread-5) Setting UserSessionNote
2024-01-29 15:03:02,852 INFO  [codelens.authenticators.CustomSetSessionVariable] (executor-thread-5) 7
2024-01-29 15:03:02,869 INFO  [codelens.authenticators.CustomSetSessionVariable] (executor-thread-5) Close Called ...
2024-01-29 15:03:13,199 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) New LOGIN Event
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) onEvent-> type=LOGIN, realmId=042e3cc7-794d-4fee-8511-97edd228f561, clientId=my-apex-application, userId=d3dc8c32-80be-44fe-83db-d95702c43887, ipAddress=127.0.0.1, auth_method=openid-connect, auth_type=code, redirect_uri=https://gcfb3a5837b74d7-jk6w3t9dqwhxl81e.adb.eu-milan-1.oraclecloudapps.com/ords/apex_authentication.callback, consent=no_consent_required, code_id=fb4c9292-9a26-4dd1-a71f-fa96f1f30c45, username=x@y.z
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) Printing event details
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) event attribute auth_method : openid-connect
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) event attribute auth_type : code
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) event attribute redirect_uri : https://xyz.adb.eu-milan-1.oraclecloudapps.com/ords/apex_authentication.callback
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) event attribute consent : no_consent_required
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) event attribute code_id : fb4c9292-9a26-4dd1-a71f-fa96f1f30c45
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) event attribute username : x@y.z
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) Printing session details
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) Printing auth note
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) auth_note: 
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) Print user session note
2024-01-29 15:03:13,200 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) sess_note: 
2024-01-29 15:03:13,201 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) Printing user details
2024-01-29 15:03:13,201 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) user detail firstName : [Adam]
2024-01-29 15:03:13,201 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) user detail lastName : [M]
2024-01-29 15:03:13,201 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) user detail email : [x@y.z]
2024-01-29 15:03:13,201 DEBUG [com.cevher.keycloak.CustomEventListenerProvider] (executor-thread-8) user detail username : [x@y.z]

What am I doing wrong? Thanks.