diff --git a/audit/jpa/src/test/resources/META-INF/persistence.xml b/audit/jpa/src/test/resources/META-INF/persistence.xml
deleted file mode 100755
index f537808fef..0000000000
--- a/audit/jpa/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- org.hibernate.ejb.HibernatePersistence
-
- org.keycloak.audit.jpa.EventEntity
-
- true
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/connections/jpa/src/main/java/org/keycloak/connections/jpa/DefaultJpaConnectionProviderFactory.java b/connections/jpa/src/main/java/org/keycloak/connections/jpa/DefaultJpaConnectionProviderFactory.java
index 8f790c9299..e39877bd9b 100644
--- a/connections/jpa/src/main/java/org/keycloak/connections/jpa/DefaultJpaConnectionProviderFactory.java
+++ b/connections/jpa/src/main/java/org/keycloak/connections/jpa/DefaultJpaConnectionProviderFactory.java
@@ -1,11 +1,14 @@
package org.keycloak.connections.jpa;
+import org.hibernate.ejb.AvailableSettings;
import org.keycloak.Config;
import org.keycloak.models.KeycloakSession;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
/**
@@ -14,7 +17,8 @@ import java.util.Properties;
public class DefaultJpaConnectionProviderFactory implements JpaConnectionProviderFactory {
private volatile EntityManagerFactory emf;
- private String unitName;
+
+ private Config.Scope config;
@Override
public JpaConnectionProvider create(KeycloakSession session) {
@@ -40,29 +44,59 @@ public class DefaultJpaConnectionProviderFactory implements JpaConnectionProvide
@Override
public void init(Config.Scope config) {
- unitName = config.get("unitName", "jpa-keycloak-identity-store");
+ this.config = config;
}
private void lazyInit() {
if (emf == null) {
synchronized (this) {
if (emf == null) {
- emf = Persistence.createEntityManagerFactory(unitName, getHibernateProperties());
+ String unitName = config.get("unitName");
+ Map properties = new HashMap();
+
+ // Only load config from keycloak-server.json if unitName is not specified
+ if (unitName == null) {
+ unitName = "keycloak-default";
+
+ String dataSource = config.get("dataSource");
+ if (dataSource != null) {
+ if (config.getBoolean("jta", false)) {
+ properties.put(AvailableSettings.JTA_DATASOURCE, dataSource);
+ } else {
+ properties.put(AvailableSettings.NON_JTA_DATASOURCE, dataSource);
+ }
+ } else {
+ properties.put(AvailableSettings.JDBC_URL, config.get("url"));
+ properties.put(AvailableSettings.JDBC_DRIVER, config.get("driver"));
+
+ String driverDialect = config.get("driverDialect");
+ if (driverDialect != null && driverDialect.length() > 0) {
+ properties.put("hibernate.dialect", driverDialect);
+ }
+
+ String user = config.get("user");
+ if (user != null) {
+ properties.put(AvailableSettings.JDBC_USER, user);
+ }
+ String password = config.get("password");
+ if (password != null) {
+ properties.put(AvailableSettings.JDBC_PASSWORD, password);
+ }
+ }
+
+ String databaseSchema = config.get("databaseSchema", "validate");
+ if (databaseSchema != null) {
+ properties.put("hibernate.hbm2ddl.auto", databaseSchema);
+ }
+
+ properties.put("hibernate.show_sql", config.getBoolean("showSql", false));
+ properties.put("hibernate.format_sql", config.getBoolean("formatSql", true));
+ }
+
+ emf = Persistence.createEntityManagerFactory(unitName, properties);
}
}
}
}
- private Properties getHibernateProperties() {
- Properties result = new Properties();
-
- for (Object property : System.getProperties().keySet()) {
- if (property.toString().startsWith("hibernate.")) {
- String propValue = System.getProperty(property.toString());
- result.put(property, propValue);
- }
- }
- return result;
- }
-
}
diff --git a/project-integrations/aerogear-ups/auth-server/src/main/resources/META-INF/persistence.xml b/connections/jpa/src/main/resources/META-INF/persistence.xml
similarity index 85%
rename from project-integrations/aerogear-ups/auth-server/src/main/resources/META-INF/persistence.xml
rename to connections/jpa/src/main/resources/META-INF/persistence.xml
index f041f731b5..6c0efe9c23 100755
--- a/project-integrations/aerogear-ups/auth-server/src/main/resources/META-INF/persistence.xml
+++ b/connections/jpa/src/main/resources/META-INF/persistence.xml
@@ -2,8 +2,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
-
- java:jboss/datasources/ExampleDS
+
org.keycloak.models.jpa.entities.ApplicationEntity
org.keycloak.models.jpa.entities.CredentialEntity
org.keycloak.models.jpa.entities.OAuthClientEntity
@@ -14,8 +13,8 @@
org.keycloak.models.jpa.entities.SocialLinkEntity
org.keycloak.models.jpa.entities.AuthenticationLinkEntity
org.keycloak.models.jpa.entities.UserEntity
- org.keycloak.models.jpa.entities.UserAttributeEntity
org.keycloak.models.jpa.entities.UserRequiredActionEntity
+ org.keycloak.models.jpa.entities.UserAttributeEntity
org.keycloak.models.jpa.entities.UserRoleMappingEntity
org.keycloak.models.jpa.entities.ScopeMappingEntity
@@ -28,9 +27,5 @@
org.keycloak.audit.jpa.EventEntity
true
-
-
-
-
diff --git a/distribution/war-zip/pom.xml b/distribution/war-zip/pom.xml
index d0ddb28a23..86f55c6003 100755
--- a/distribution/war-zip/pom.xml
+++ b/distribution/war-zip/pom.xml
@@ -62,7 +62,7 @@
- ${project.build.directory}/unpacked/deployments/auth-server.war/WEB-INF/classes/META-INF/persistence.xml
+ ${project.build.directory}/unpacked/deployments/auth-server.war/WEB-INF/classes/META-INF/keycloak-server.json
java:jboss/datasources/ExampleDS
diff --git a/model/jpa/src/test/resources/META-INF/persistence.xml b/model/jpa/src/test/resources/META-INF/persistence.xml
deleted file mode 100755
index 8b3c6d7bba..0000000000
--- a/model/jpa/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
- org.hibernate.ejb.HibernatePersistence
-
- org.keycloak.models.jpa.entities.ApplicationEntity
- org.keycloak.models.jpa.entities.CredentialEntity
- org.keycloak.models.jpa.entities.OAuthClientEntity
- org.keycloak.models.jpa.entities.RealmEntity
- org.keycloak.models.jpa.entities.RequiredCredentialEntity
- org.keycloak.models.jpa.entities.AuthenticationProviderEntity
- org.keycloak.models.jpa.entities.RoleEntity
- org.keycloak.models.jpa.entities.SocialLinkEntity
- org.keycloak.models.jpa.entities.AuthenticationLinkEntity
- org.keycloak.models.jpa.entities.UserEntity
- org.keycloak.models.jpa.entities.UserAttributeEntity
- org.keycloak.models.jpa.entities.UserRequiredActionEntity
- org.keycloak.models.jpa.entities.UserRoleMappingEntity
- org.keycloak.models.jpa.entities.ScopeMappingEntity
-
- true
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/model/realms-jpa/src/test/resources/META-INF/persistence.xml b/model/realms-jpa/src/test/resources/META-INF/persistence.xml
deleted file mode 100755
index a150d05038..0000000000
--- a/model/realms-jpa/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-
-
- org.hibernate.ejb.HibernatePersistence
-
- org.keycloak.models.jpa.entities.ApplicationEntity
- org.keycloak.models.jpa.entities.CredentialEntity
- org.keycloak.models.jpa.entities.OAuthClientEntity
- org.keycloak.models.jpa.entities.RealmEntity
- org.keycloak.models.jpa.entities.RequiredCredentialEntity
- org.keycloak.models.jpa.entities.AuthenticationProviderEntity
- org.keycloak.models.jpa.entities.RoleEntity
- org.keycloak.models.jpa.entities.SocialLinkEntity
- org.keycloak.models.jpa.entities.AuthenticationLinkEntity
- org.keycloak.models.jpa.entities.UserEntity
- org.keycloak.models.jpa.entities.UserSessionEntity
- org.keycloak.models.jpa.entities.ClientUserSessionAssociationEntity
- org.keycloak.models.jpa.entities.UserRoleMappingEntity
- org.keycloak.models.jpa.entities.UsernameLoginFailureEntity
- org.keycloak.models.jpa.entities.ScopeMappingEntity
-
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/model/users-jpa/src/test/resources/META-INF/persistence.xml b/model/users-jpa/src/test/resources/META-INF/persistence.xml
deleted file mode 100755
index 208c895dce..0000000000
--- a/model/users-jpa/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
- org.hibernate.ejb.HibernatePersistence
-
- org.keycloak.models.users.jpa.entities.UserAttributeEntity
- org.keycloak.models.users.jpa.entities.UserCredentialEntity
- org.keycloak.models.users.jpa.entities.UserRoleMappingEntity
- org.keycloak.models.users.jpa.entities.UserEntity
-
- true
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/project-integrations/aerogear-ups/auth-server/src/main/webapp/WEB-INF/classes/META-INF/keycloak-server.json b/project-integrations/aerogear-ups/auth-server/src/main/webapp/WEB-INF/classes/META-INF/keycloak-server.json
index fd02151ac8..a1e472e577 100755
--- a/project-integrations/aerogear-ups/auth-server/src/main/webapp/WEB-INF/classes/META-INF/keycloak-server.json
+++ b/project-integrations/aerogear-ups/auth-server/src/main/webapp/WEB-INF/classes/META-INF/keycloak-server.json
@@ -10,16 +10,24 @@
}
},
- "model": {
+ "realm": {
"provider": "jpa"
},
- "userSessions": {
- "provider" : "mem"
+ "user": {
+ "provider": "${keycloak.user.provider:jpa}"
},
- "modelCache": {
- "provider": "${keycloak.model.cache.provider:}"
+ "userSessions": {
+ "provider" : "${keycloak.userSessions.provider:mem}"
+ },
+
+ "realmCache": {
+ "provider": "${keycloak.realm.cache.provider:mem}"
+ },
+
+ "userCache": {
+ "provider": "${keycloak.user.cache.provider:mem}"
},
"timer": {
@@ -49,5 +57,12 @@
"scheduled": {
"interval": 900
+ },
+
+ "connectionsJpa": {
+ "default": {
+ "dataSource": "java:jboss/datasources/ExampleDS",
+ "databaseSchema": "update"
+ }
}
}
\ No newline at end of file
diff --git a/server/src/main/resources/META-INF/keycloak-server.json b/server/src/main/resources/META-INF/keycloak-server.json
index 7c6d9f894f..e77571052b 100755
--- a/server/src/main/resources/META-INF/keycloak-server.json
+++ b/server/src/main/resources/META-INF/keycloak-server.json
@@ -57,5 +57,12 @@
"scheduled": {
"interval": 900
+ },
+
+ "connectionsJpa": {
+ "default": {
+ "dataSource": "java:jboss/datasources/ExampleDS",
+ "databaseSchema": "update"
+ }
}
}
\ No newline at end of file
diff --git a/server/src/main/resources/META-INF/persistence.xml b/server/src/main/resources/META-INF/persistence.xml
deleted file mode 100755
index feb9d2dc65..0000000000
--- a/server/src/main/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
- java:jboss/datasources/ExampleDS
- org.keycloak.models.jpa.entities.ApplicationEntity
- org.keycloak.models.jpa.entities.CredentialEntity
- org.keycloak.models.jpa.entities.OAuthClientEntity
- org.keycloak.models.jpa.entities.RealmEntity
- org.keycloak.models.jpa.entities.RequiredCredentialEntity
- org.keycloak.models.jpa.entities.AuthenticationProviderEntity
- org.keycloak.models.jpa.entities.RoleEntity
- org.keycloak.models.jpa.entities.SocialLinkEntity
- org.keycloak.models.jpa.entities.AuthenticationLinkEntity
- org.keycloak.models.jpa.entities.UserEntity
- org.keycloak.models.jpa.entities.UserRequiredActionEntity
- org.keycloak.models.jpa.entities.UserAttributeEntity
- org.keycloak.models.jpa.entities.UserRoleMappingEntity
- org.keycloak.models.jpa.entities.ScopeMappingEntity
-
-
- org.keycloak.models.sessions.jpa.entities.ClientUserSessionAssociationEntity
- org.keycloak.models.sessions.jpa.entities.UserSessionEntity
- org.keycloak.models.sessions.jpa.entities.UsernameLoginFailureEntity
-
-
- org.keycloak.audit.jpa.EventEntity
-
- true
-
-
-
-
-
-
diff --git a/testsuite/integration/src/main/resources/META-INF/keycloak-server.json b/testsuite/integration/src/main/resources/META-INF/keycloak-server.json
index c5f967763d..4d743491e7 100755
--- a/testsuite/integration/src/main/resources/META-INF/keycloak-server.json
+++ b/testsuite/integration/src/main/resources/META-INF/keycloak-server.json
@@ -56,6 +56,17 @@
"interval": 900
},
+ "connectionsJpa": {
+ "default": {
+ "url": "${keycloak.connectionsJpa.url:jdbc:h2:mem:test}",
+ "driver": "${keycloak.connectionsJpa.driver:org.h2.Driver}",
+ "driverDialect": "${keycloak.connectionsJpa.driverDialect:}",
+ "user": "${keycloak.connectionsJpa.user:sa}",
+ "password": "${keycloak.connectionsJpa.password:}",
+ "databaseSchema": "${keycloak.connectionsJpa.databaseSchema:create-drop}"
+ }
+ },
+
"connectionsMongo": {
"default": {
"host": "${keycloak.connectionsMongo.host:127.0.0.1}",
@@ -64,5 +75,4 @@
"clearOnStartup": "${keycloak.connectionsMongo.clearOnStartup:false}"
}
}
-
}
\ No newline at end of file
diff --git a/testsuite/integration/src/main/resources/META-INF/persistence.xml b/testsuite/integration/src/main/resources/META-INF/persistence.xml
deleted file mode 100755
index 9c04a330d5..0000000000
--- a/testsuite/integration/src/main/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
- org.hibernate.ejb.HibernatePersistence
-
- org.keycloak.models.jpa.entities.ApplicationEntity
- org.keycloak.models.jpa.entities.CredentialEntity
- org.keycloak.models.jpa.entities.OAuthClientEntity
- org.keycloak.models.jpa.entities.RealmEntity
- org.keycloak.models.jpa.entities.RequiredCredentialEntity
- org.keycloak.models.jpa.entities.AuthenticationProviderEntity
- org.keycloak.models.jpa.entities.RoleEntity
- org.keycloak.models.jpa.entities.SocialLinkEntity
- org.keycloak.models.jpa.entities.AuthenticationLinkEntity
- org.keycloak.models.jpa.entities.UserEntity
- org.keycloak.models.jpa.entities.UserAttributeEntity
- org.keycloak.models.jpa.entities.UserRequiredActionEntity
- org.keycloak.models.jpa.entities.UserRoleMappingEntity
- org.keycloak.models.jpa.entities.ScopeMappingEntity
-
-
- org.keycloak.models.sessions.jpa.entities.ClientUserSessionAssociationEntity
- org.keycloak.models.sessions.jpa.entities.UserSessionEntity
- org.keycloak.models.sessions.jpa.entities.UsernameLoginFailureEntity
-
-
- org.keycloak.audit.jpa.EventEntity
-
- true
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java
index 746a87a418..e0aa2beb94 100755
--- a/testsuite/integration/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java
+++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java
@@ -41,7 +41,7 @@ public class ExportImportTest {
@Override
protected void before() throws Throwable {
- if (System.getProperty("hibernate.connection.url") == null) {
+ if (System.getProperty("keycloak.connectionsJpa.url") == null) {
String baseExportImportDir = getExportImportTestDirectory();
File oldDBFile = new File(baseExportImportDir, "keycloakDB.h2.db");
@@ -50,8 +50,8 @@ public class ExportImportTest {
}
String dbDir = baseExportImportDir + "/keycloakDB";
- System.setProperty("hibernate.connection.url", "jdbc:h2:file:" + dbDir + ";DB_CLOSE_DELAY=-1");
- System.setProperty("hibernate.hbm2ddl.auto", "update");
+ System.setProperty("keycloak.connectionsJpa.url", "jdbc:h2:file:" + dbDir + ";DB_CLOSE_DELAY=-1");
+ System.setProperty("keycloak.connectionsJpa.databaseSchema", "update");
setupDone = true;
}
}
@@ -60,8 +60,8 @@ public class ExportImportTest {
protected void after() {
if (setupDone) {
Properties sysProps = System.getProperties();
- sysProps.remove("hibernate.connection.url");
- sysProps.remove("hibernate.hbm2ddl.auto");
+ sysProps.remove("keycloak.connectionsJpa.url");
+ sysProps.remove("keycloak.connectionsJpa.databaseSchema");
}
}
};
diff --git a/testsuite/performance/src/test/resources/META-INF/persistence.xml b/testsuite/performance/src/test/resources/META-INF/persistence.xml
deleted file mode 100755
index 4850a25d5f..0000000000
--- a/testsuite/performance/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- org.hibernate.ejb.HibernatePersistence
-
- org.keycloak.models.jpa.entities.ApplicationEntity
- org.keycloak.models.jpa.entities.CredentialEntity
- org.keycloak.models.jpa.entities.OAuthClientEntity
- org.keycloak.models.jpa.entities.RealmEntity
- org.keycloak.models.jpa.entities.RequiredCredentialEntity
- org.keycloak.models.jpa.entities.AuthenticationProviderEntity
- org.keycloak.models.jpa.entities.RoleEntity
- org.keycloak.models.jpa.entities.SocialLinkEntity
- org.keycloak.models.jpa.entities.AuthenticationLinkEntity
- org.keycloak.models.jpa.entities.UserEntity
- org.keycloak.models.jpa.entities.UserAttributeEntity
- org.keycloak.models.jpa.entities.UserRequiredActionEntity
- org.keycloak.models.jpa.entities.UserSessionEntity
- org.keycloak.models.jpa.entities.ClientUserSessionAssociationEntity
- org.keycloak.models.jpa.entities.UsernameLoginFailureEntity
- org.keycloak.models.jpa.entities.UserRoleMappingEntity
- org.keycloak.models.jpa.entities.ScopeMappingEntity
-
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/testsuite/tools/src/main/resources/META-INF/persistence.xml b/testsuite/tools/src/main/resources/META-INF/persistence.xml
deleted file mode 100755
index 4e3d279669..0000000000
--- a/testsuite/tools/src/main/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
- java:jboss/datasources/KeycloakDS
- org.keycloak.models.jpa.entities.ApplicationEntity
- org.keycloak.models.jpa.entities.CredentialEntity
- org.keycloak.models.jpa.entities.OAuthClientEntity
- org.keycloak.models.jpa.entities.RealmEntity
- org.keycloak.models.jpa.entities.RequiredCredentialEntity
- org.keycloak.models.jpa.entities.AuthenticationProviderEntity
- org.keycloak.models.jpa.entities.RoleEntity
- org.keycloak.models.jpa.entities.SocialLinkEntity
- org.keycloak.models.jpa.entities.AuthenticationLinkEntity
- org.keycloak.models.jpa.entities.UserEntity
- org.keycloak.models.jpa.entities.UserAttributeEntity
- org.keycloak.models.jpa.entities.UserRequiredActionEntity
- org.keycloak.models.jpa.entities.UserSessionEntity
- org.keycloak.models.jpa.entities.ClientUserSessionAssociationEntity
- org.keycloak.models.jpa.entities.UsernameLoginFailureEntity
- org.keycloak.models.jpa.entities.UserRoleMappingEntity
- org.keycloak.models.jpa.entities.ScopeMappingEntity
-
- true
-
-
-
-
-
-
-
- java:jboss/datasources/ExampleDS
- org.keycloak.audit.jpa.EventEntity
-
- true
-
-
-
-
-
-
-