Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom User Storage Provider JPA runtime provided properties #570

Open
carlosmtobon opened this issue Jul 1, 2024 · 1 comment
Open

Comments

@carlosmtobon
Copy link

Describe the bug

Hello I have a Custom User Storage provider that connects to a MySQL database using JPA. The user will provides the config details using the UI (via ProviderConfigurationBuilder). In the Factory class I am trying to do something like this

        Map<String, String> properties = new HashMap<>();
        properties.put("jakarta.persistence.jdbc.url", model.get(CONFIG_KEY_JDBC_URL));
        properties.put("jakarta.persistence.jdbc.user", model.get(CONFIG_KEY_DB_USERNAME));
        properties.put("jakarta.persistence.jdbc.password", model.get(CONFIG_KEY_DB_PASSWORD));
        properties.put("jakarta.persistence.jdbc.driver", model.get(CONFIG_KEY_JDBC_DRIVER));
        properties.put("hibernate.hbm2ddl.auto", "update");
        properties.put("hibernate.show_sql", "true");

        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("dynamic-persistence-unit", properties);

but I am getting
Caused by: jakarta.persistence.PersistenceException: The FastbootHibernateProvider PersistenceProvider can not support runtime provided properties. Make sure you set all properties you need in the configuration resources before building the application.

What is the correct way to handle a runtime configuration?

Things I've tried:
I've tried adding quarkus.properties and matching the data source names with the persistence.xml

Sorry if this has been answered before, just not clear since examples I see don't provide runtime configurations.

Version

25.0.1

Expected behavior

Allow runtime configuration for external database connection for user storage

Actual behavior

getting an error about needing to provide the configuration at build time

How to Reproduce?

  • Place provider in providers folder along with db connector
  • Start keycloak in dev mode
  • Configure the custom user storage via UI (connection succeeds)
  • try to query users

Anything else?

The only time I have seen this provider work for me was when I initially tested against a Keycloak embedded Spring boot app using this article.

@carlosmtobon
Copy link
Author

link to article

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant