[keycloak-user] ClassNotFoundException: Custom UserStorageProvider
Bill Burke
bburke at redhat.com
Thu Mar 2 09:17:50 EST 2017
its very difficult trying to hand code JPA. There's a lot of
dependencies you have to manually import through
jboss-deployment-structure.xml and/or module.xml files. This is the
reason I wrote a Keycloak deployer.
https://github.com/keycloak/keycloak/tree/master/examples/providers/user-storage-jpa
https://keycloak.gitbooks.io/documentation/server_development/topics/user-storage/packaging.html
https://keycloak.gitbooks.io/documentation/server_development/topics/user-storage/javaee.html
On 3/2/17 5:02 AM, Marek Posolda wrote:
> Hi,
>
> it seems that it is Hibernate, which is not able to find your classes. I
> guess that you are trying to configure JDBC URL, user and password
> directly in persistence.xml and that's maybe an issue.
>
> I suggest to rather configure the datasource in standalone.xml and then
> use the property "jta-data-source" in your persistence.xml pointing to
> that. Besides classloading issues, another advantage is, that you will
> automatically have connection-pooling, connection liveness checks
> (optional) etc. See our example "providers/user-storage-jpa" for
> inspiration, which is doing the same.
>
> Marek
>
> On 02/03/17 10:42, Danny Trunk wrote:
>> Hello,
>>
>> I've implemented a custom User Storage Provider to connect to a
>> configurable (external) database through Hibernate/JDBC:
>>
>> public class MyUserStorageProviderFactory implements
>> UserStorageProviderFactory<MyUserStorageProvider> {
>> // ...
>> public MyUserStorageProvider create(KeycloakSession session,
>> ComponentModel model) {
>> logger.info(">>>>>> Creating factory");
>> PersistenceConfig config = new
>> PersistenceConfig(model.getConfig());
>> entityManagerFactory = new
>> HibernatePersistenceProvider().createContainerEntityManagerFactory(getPersistenceUnitInfo(),
>> config.asProperties());
>> entityManager = entityManagerFactory.createEntityManager();
>> return new MyUserStorageProvider(entityManager, session, model);
>> }
>> // ...
>> }
>>
>> In src/main/resources/META-INF I've placed a file named
>> jboss-deployment-structure.xml:
>> <?xml version="1.0" ?>
>> <jboss-deployment-structure>
>> <deployment>
>> <dependencies>
>> <module name="org.hibernate" />
>> <module name="org.jboss.logging" />
>> <module name="org.keycloak.keycloak-core" />
>> <module name="org.keycloak.keycloak-server-spi" />
>> <module name="org.postgresql" />
>> </dependencies>
>> </deployment>
>> </jboss-deployment-structure>
>>
>> Although there's a dependency for org.postgresql I'm getting a
>> ClassNotFoundException when trying to authenticate:
>> WARN [org.keycloak.services] (default task-6) KC-SERVICES0013: Failed
>> authentication: org.hibernate.service.spi.ServiceException: Unable to
>> create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
>> ...
>> Caused by:
>> org.hibernate.boot.registry.classloading.spi.ClassLoadingException:
>> Unable to load class [org.postgresql.Driver]
>> ...
>> Caused by: java.lang.ClassNotFoundException: Could not load requested
>> class : org.postgresql.Driver
>>
>> PostgreSQL is deployed as module as described here:
>> https://keycloak.gitbooks.io/server-installation-and-configuration/content/topics/database/jdbc.html
>> _______________________________________________
>> keycloak-user mailing list
>> keycloak-user at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/keycloak-user
>
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user
More information about the keycloak-user
mailing list