REST Provider only for specific Realm


I currently writing a custom REST Provider and ideally the interface should only be available at a specific realm. Is there any solution to achieve this?

Thank you,


Not that I know of. I have had this requirement before, and I just hard coded the realm in my implementation and just returned a 403 for any access for another realm.

Thanks for your fast response. After a little bit of research I also found a similar approach. Instead of hard code it into the provider itself, you can make the distinction in the “create()” - method of the factory. It’s now looks something like this:

  public RealmResourceProvider create(KeycloakSession keycloakSession) {
    var realm = keycloakSession.getContext().getRealm();

      return new CustomResourceProvider(keycloakSession);

    return null;

Keycloak itself returns a “404” if you make a request on any other realm.

1 Like