Hi All,
I’m implementing a UserFederationProviderFactory and want to create an EntityManagerFactory from one of its methods. I have packaged up a persistence.xml in the META-INF folder of the SPI jar file and deployed this as a module to the keycloak
standalone server.
My module.xml looks like this…
<module xmlns="urn:jboss:module:1.3" name="acme.keycloak-acme-user-federation">
<resources>
<resource-root path="keycloak-acme-user-federation-1.0.0.jar">
<filter>
<include path="META-INF/**"/>
</filter>
</resource-root>
</resources>
<dependencies>
<module name="org.keycloak.keycloak-core"/>
<module name="org.keycloak.keycloak-server-spi"/>
<module name="javax.api"/>
<module name="javaee.api"/>
<module name="org.hibernate" />
<module name="org.jboss.ws.cxf.jbossws-cxf-client"/>
</dependencies>
</module>
In my UserFederationProviderFactory I have a method like this…
private EntityManagerFactory getEntityManagerFactory(UserFederationProviderModel model) {
if (emf == null) {
logger.trace("Creating entityManagerFactory...");
Map<String, String> config = model.getConfig();
Properties p = new Properties();
// for now just use hibernate built in connection factory
p.put("hibernate.connection.driver_class", config.get(DATABASE_DRIVER_CLASS_NAME));
p.put("hibernate.connection.url", config.get(DATABASE_URL));
p.put("hibernate.connection.username", config.get(DATABASE_USER));
p.put("hibernate.connection.password", config.get(DATABASE_PASSWORD));
p.put("hibernate.show_sql", "true");
p.put("hibernate.format_sql", "true");
emf = Persistence.createEntityManagerFactory("acmeEntities", p);
}
return emf;
}
When this method is called, it always returns the error “No Persistence provider for EntityManager named acmeEntities”.
I’m 90% sure this is to do with the ClassLoader being used by Persistence not being able to see the META-INF/persistence.xml packaged up in the keycloak-acme-user-federation-1.0.0.jar. Does anyone have an idea what I need to do to my module
configuration to get this working?
Thanks,
Anthony Fryer