I am working on a Keycloak user federation application that uses the user-storage-jpa from keycloak-quickstarts. I configured it to use a MySQL database as shown in the following quarkus.properties file:
quarkus.datasource.custom-user-store.jdbc.transactions=xa
quarkus.datasource.custom-user-store.db-kind=mysql
quarkus.datasource.custom-user-store.username=username
quarkus.datasource.custom-user-store.password=password
quarkus.datasource.custom-user-store.jdbc.url=jdbc:mysql://localhost:3308/my_db
quarkus.datasource.custom-user-store.health.enabled=true
quarkus.datasource.keycloak-user-store.jdbc.transactions=xa
quarkus.datasource.keycloak-user-store.db-kind=mysql
quarkus.datasource.keycloak-user-store.username=username
quarkus.datasource.keycloak-user-store.password=password
quarkus.datasource.keycloak-user-store.jdbc.url=jdbc:mysql://localhost:3308/keycloak_db
quarkus.datasource.keycloak-user-store.health.enabled=true
However, I want to set the JDBC URL (quarkus.datasource.custom-user-store.jdbc.url
and quarkus.datasource.keycloak-user-store.jdbc.url
), along with the credentials, dynamically at runtime, while Keycloak is running, based on user input from the Keycloak admin console. The JDBC URL is retrieved from the Keycloak model as follows:
String jdbcUrl = model.getConfig().getFirst(String.valueOf(ConfigProperties.JDBC_URL));
Here is the admin console where the user types in the database credentials as well as the JDBC URL.
I understand that Quarkus reads the quarkus.properties file at build time. Therefore, I am not sure how I can override the JDBC URL at runtime, while Keycloak is running. Is there a way to create a datasource at runtime with the JDBC URL set dynamically? If so, how can I achieve this?
I would appreciate any guidance or suggestions. Thanks in advance!
I tried using the System.property() but it is not working because the involved properties are not set before starting Keycloak.