# Get ComponentModel in UserStorageProviderFactory

**URL:** <https://forum.keycloak.org/t/get-componentmodel-in-userstorageproviderfactory/23896>\
**Category:** Miscellanaeous\
**Created:** [January 2, 2024, 5:30pm UTC](https://forum.keycloak.org/t/get-componentmodel-in-userstorageproviderfactory/23896 "2024-01-02T17:30:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carl](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/carl/32/10443_2.png) [@Carl](https://forum.keycloak.org/u/Carl)\
**Post date:** [January 2, 2024, 5:30pm UTC](https://forum.keycloak.org/t/get-componentmodel-in-userstorageproviderfactory/23896/1 "2024-01-02T17:30:19Z")

</div>

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

---

<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:** [January 2, 2024, 6:05pm UTC](https://forum.keycloak.org/t/get-componentmodel-in-userstorageproviderfactory/23896/2 "2024-01-02T18:05:04Z")

</div>

> [@Carl](#):
>
> 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.

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()`.

---

<div class="post-metadata">

**Author:** ![Carl](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/carl/32/10443_2.png) [@Carl](https://forum.keycloak.org/u/Carl)\
**Post date:** [January 2, 2024, 6:55pm UTC](https://forum.keycloak.org/t/get-componentmodel-in-userstorageproviderfactory/23896/3 "2024-01-02T18:55:50Z")

</div>

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.

---

<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:** [January 2, 2024, 7:11pm UTC](https://forum.keycloak.org/t/get-componentmodel-in-userstorageproviderfactory/23896/4 "2024-01-02T19:11:07Z")

</div>

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

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

```
