DataSource dependency injection in custom User Storage Provider

I’m trying to implement a custom user storage provider for keycloak 17. I need an DB connection and would like to use connection pool and data source configuration. I seems to get the configuration, but I don’t get dependency injection to happen. Is it possible to do, is there any examples for it somewhere?

I’m also interested in the answer. Impossible to get working even following documentation with multiple PersistentUnits Quarkus - Using Hibernate ORM and JPA. The entities are always attached to the keycloak-default PersistentUnit …

I’m currently struggling to get EntetyManager. Were you able to get it and how?

My EntityManager is not injected but I can see my Entities registering to the default PersistentUnit “keycloak-default”.

Seems, that CDI (dependency injection) is not supported at all (according to documentation). Seems that Factory is not created as a bean and hence nothing injected. Also query through JNDI probably won’t work either, not supported by quarkus. The hibernate entityManager, which is returned from session argument of the create() method is indeed only target main keycloak DB. I also haven’t found any other way to get other entityManagers for hibernate (lack of JNDI and @Injection or I miss something). Maybe it is possible to create factory instance directly. There is one possibility to get Agroal connection pool for a datasource configured in (io.quarkus.agroal.runtime.DataSources.fromName() ), but also don’t seem to work properly (some strange delay on query).

Next thing to try is probably to attach custom MariaDbPoolDataSource to the componentModel (setNote() probably can be used for it) during configuration check.

This should be fixed with next version.
Here’s the link to the PR, there’s is also included the link to the adjusted quickstart example.