Custom captcha: session getAttribute() returns null


I am writing a custom Captcha, it generates an random Text, saves it the session and is suppose to verify it against the formData.
When validating the Session attribute is always null, and I don’t see why:

The setup is from the recaptcha example:
In the validate method session.getAttribute(“captchaText”) is always null.

public class RegistrationRecaptcha implements FormAction, FormActionFactory, ConfiguredProvider 
    public void buildPage(FormContext context, LoginFormsProvider form) {
        form.setAttribute("captchaRequired", true);
        String captchaText = Captcha.generateText();
        context.getSession().setAttribute("captchaText", captchaText);
        form.setAttribute("captchaImage", Captcha.generateImage(captchaText));

    public void validate(ValidationContext context) {
        MultivaluedMap<String, String> formData = 
        context.getHttpRequest().getDecodedFormParameters();"Attribute captchaText: " + context.getSession().getAttribute("captchaText"));
        if (!formData.getFirst("captcha").equals(session.getAttribute("captchaText"))) {
  "validate fails");

session = context.getSession().getKeycloakSessionFactory().create();

Creating a new session like this helped