Getting specific storage provider in custom SPI

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.

I think “ldap” is no the componentId.

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

Yes I tried that too, but it also gives null

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). I wish there was better documentation on the internals, but I’ve never been able to find it.

1 Like

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.

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.

1 Like