# REST Provider only for specific Realm

**URL:** <https://forum.keycloak.org/t/rest-provider-only-for-specific-realm/17966>\
**Category:** Extending the server\
**Created:** [October 18, 2022, 10:20am UTC](https://forum.keycloak.org/t/rest-provider-only-for-specific-realm/17966 "2022-10-18T10:20:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@Tobias](https://forum.keycloak.org/u/Tobias)\
**Post date:** [October 18, 2022, 10:20am UTC](https://forum.keycloak.org/t/rest-provider-only-for-specific-realm/17966/1 "2022-10-18T10:20:18Z")

</div>

Hello,

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,

Tobias

---

<div class="post-metadata">

**Author:** ![xgp](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/xgp/32/2589_2.png) [@xgp](https://forum.keycloak.org/u/xgp)\
**Post date:** [October 18, 2022, 10:29am UTC](https://forum.keycloak.org/t/rest-provider-only-for-specific-realm/17966/2 "2022-10-18T10:29:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@Tobias](https://forum.keycloak.org/u/Tobias)\
**Post date:** [October 18, 2022, 11:30am UTC](https://forum.keycloak.org/t/rest-provider-only-for-specific-realm/17966/3 "2022-10-18T11:30:53Z")

</div>

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:

```auto
  @Override
  public RealmResourceProvider create(KeycloakSession keycloakSession) {
    var realm = keycloakSession.getContext().getRealm();

    if(realm.getName().equals("YourRealm")){
      return new CustomResourceProvider(keycloakSession);
    }

    return null;
  }

```

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