# Getting specific storage provider in custom SPI

**URL:** <https://forum.keycloak.org/t/getting-specific-storage-provider-in-custom-spi/20009>\
**Category:** Extending the server\
**Tags:** ldap\
**Created:** [February 2, 2023, 8:26am UTC](https://forum.keycloak.org/t/getting-specific-storage-provider-in-custom-spi/20009 "2023-02-02T08:26:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![keaz](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/keaz/32/7607_2.png) [@keaz](https://forum.keycloak.org/u/keaz)\
**Post date:** [February 2, 2023, 8:26am UTC](https://forum.keycloak.org/t/getting-specific-storage-provider-in-custom-spi/20009/1 "2023-02-02T08:26:57Z")

</div>

We have configured multiple LDAP servers with Keycloak and we want to authenticate users against a specific LDAP depending on their email domain. To achieve this I created a customer Authenticator and I’m trying to get specific LDAP in the code.  
I tried this

> sesstion.getComponentProvider(UserStorageProvider.class,“ldap”)

and other options but I’m getting null.

---

<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:** [February 2, 2023, 8:42am UTC](https://forum.keycloak.org/t/getting-specific-storage-provider-in-custom-spi/20009/2 "2023-02-02T08:42:10Z")

</div>

I think “ldap” is no the `componentId`.

Did you try `session.getAllProviders(UserStorageProvider.class)` to see if it’s there?

---

<div class="post-metadata">

**Author:** ![keaz](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/keaz/32/7607_2.png) [@keaz](https://forum.keycloak.org/u/keaz)\
**Post date:** [February 2, 2023, 9:42am UTC](https://forum.keycloak.org/t/getting-specific-storage-provider-in-custom-spi/20009/3 "2023-02-02T09:42:00Z")

</div>

Yes I tried that too, but it also gives null

---

<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:** [February 2, 2023, 9:50am UTC](https://forum.keycloak.org/t/getting-specific-storage-provider-in-custom-spi/20009/4 "2023-02-02T09:50:58Z")

</div>

In order to get the correct `ComponentModel`, to use with `session.getProvider(UserStorageProvider.class, componentModel)`, I had to use the `realmModel.getComponentsStream()` method [RealmModel (Keycloak Docs Distribution 20.0.3 API)](https://www.keycloak.org/docs-api/20.0.3/javadocs/org/keycloak/models/RealmModel.html#getComponentsStream()). I wish there was better documentation on the internals, but I’ve never been able to find it.

---

<div class="post-metadata">

**Author:** ![keaz](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/keaz/32/7607_2.png) [@keaz](https://forum.keycloak.org/u/keaz)\
**Post date:** [February 2, 2023, 10:16am UTC](https://forum.keycloak.org/t/getting-specific-storage-provider-in-custom-spi/20009/5 "2023-02-02T10:16:16Z")

</div>

Yes, it works, but my only concern is that they have marked this method as `session.getProvider` as deprecated.  
What is the Keyclaok version you use? I’m on 15.2 and we have the plan to upgrade to the latest stable version.

---

<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:** [February 2, 2023, 10:23am UTC](https://forum.keycloak.org/t/getting-specific-storage-provider-in-custom-spi/20009/6 "2023-02-02T10:23:10Z")

</div>

This works in 20.0.3. Everything related to storage is up in the air because of the “new” store, but I have no information on what and when changes will be made, despite having tried to find it. I have a feeling that creators of custom User Storage SPI implementations will be effectively stuck on an old version of Keycloak in the next 12-18 months, or whenever the “new” store gets released.
