Unable to use Keycloak's Hostname SPI

It appears I am misunderstanding how SPIs are supposed to work with the Keycloak XML config. Based on my (very quick) skim of the Keycloak source it appears any usage of <spi name=xx><provider results in custom jar files being unable to provide alternative implementations of that SPI. This seems unlikely.

I’m attempting to use Keycloak’s Hostname SPI. I’ve built my ProviderFactory and my Provider, and I can see from debugging keycloak that my META-INF/services/org.keycloak.urls.HostnameProviderFactory file is being loaded. I also see that my factory class is being loaded into the JVM and the no-args constructor is called.

However, the factory is never shown on the list of available factories, and directly calling it using session.getKeycloakSessionFactory().getProviderFactory(HostnameProvider.class, "my-id"); returns a null.

From tracing Keycloak it seems that my confusion has something to do with the fact that the config XML file I am using already defines <spi name="hostname"><provider name="default" ... .

In ProviderManager#load(Spi,String) I see my custom factory being loaded, but because it does not have a providerId of default it is just ignored. This is called by DefaultKeycloakSessionFactory#loadFactories(ProviderManager) , which has a large if-else that mainly differs in how it handles a provider being found in the config file. If a provider is found, it only loads SPI implementations with the same name as the one found in the config file, else it loads all SPI implementations.

X-Post Link: java - Unable to use Keycloak's Hostname SPI - Stack Overflow