Get ComponentModel in UserStorageProviderFactory

Hi,

Is there a way to get the config associated with the ComponentModel in UserStorageProviderFactory methods like init() or postInit()? Currently, I’m lazy initializing in create() but I’d like to do this all at startup. I’m not looking for a default config but one with values pulled from the admin panel.

KC 21.1.2

Thank you,
Carl

A ComponentModel is going to be for an instance of that storage provider, so there are (potentially) more than one. If you know which one you are looking for, you can get it from the RealmModel with realm.getComponent(id), or iterate through all of them with realm.getComponentsStream().

1 Like

Is there a good place to iterate over the components? The factory’s init() and postInit() methods don’t seem to have the Realm or ComponentModel available.

I’m trying to configure an Agroal JDBC connection and trying to avoid a lazy-loading performance hit on the first connections.

You can get the KeycloakSession and a RealmModel in the postInit method like this:

  @Override
  public void postInit(KeycloakSessionFactory factory) {
      KeycloakModelUtils.runJobInTransaction(factory, (KeycloakSession session) -> {
        RealmModel realm = session.realms().getRealm("myRealm");
      });
  }
1 Like