[keycloak-user] ClassNotFoundException: Custom UserStorageProvider

Danny Trunk dt at zyres.com
Thu Mar 2 04:42:48 EST 2017


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


More information about the keycloak-user mailing list