java.lang.IllegalArgumentException: Session not bound to a realm

I have updated Keycloak to v26.0.5 and I am getting this error when Keycloak is try to bootstrap realms:
java.lang.IllegalArgumentException: Session not bound to a realm

Look like realm is imported but then I am getting the error in this class:
InfinispanIdentityProviderStorageProvider

    private RealmModel getRealm() {
        **RealmModel realm = this.session.getContext().getRealm();**
        if (realm == null) {
            **throw new IllegalArgumentException("Session not bound to a realm");**
        } else {
            return realm;
        }
    }

my Dockerfile:

FROM quay.io/keycloak/keycloak:26.0.5 AS builder

WORKDIR /opt/keycloak
COPY /build/libs/platserv-keycloak*.jar /opt/keycloak/providers
COPY /config/realms /opt/keycloak/data/import

FROM quay.io/keycloak/keycloak:26.0.5
COPY --from=builder --chown=keycloak:root /opt/keycloak/ /opt/keycloak/

... other ENV vars ... 
ENV JAVA_OPTS_APPEND="-Dkeycloak.migration.replace-placeholders=true -Dkeycloak.migration.action=import -Dkeycloak.migration.provider=dir -Dkeycloak.migration.dir=/opt/keycloak/data/import -Dkeycloak.migration.strategy=OVERWRITE_EXISTING"

ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]

CMD ["start", "--verbose"]

Any idea?

Have you checked the Keycloak Github issues? I know that they made the decision not to have the new identity provider methods take a realm, which requires that the realm be set in the context. It looks like this code isn’t properly setting up the context, as is now required in things like import and some event listeners that happen outside of the request context.

Thank you for answer, the problem was JSON file name. it should be {name}-realm.json and then all was as expected!
It is very modestly mentioned here:

1 Like