keycloak-aplcache
Changes
connections/jpa/src/main/java/org/keycloak/connections/jpa/DefaultJpaConnectionProviderFactory.java 62(+48 -14)
distribution/war-zip/pom.xml 2(+1 -1)
project-integrations/aerogear-ups/auth-server/src/main/webapp/WEB-INF/classes/META-INF/keycloak-server.json 7(+7 -0)
project-integrations/README.md 1(+0 -1)
Details
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 8f790c9..e39877b 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<String, Object> properties = new HashMap<String, Object>();
+
+ // Only load config from keycloak-server.json if unitName is not specified
+ if (unitName == null) {
+ unitName = "keycloak-default";
- private Properties getHibernateProperties() {
- Properties result = new Properties();
+ 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"));
- for (Object property : System.getProperties().keySet()) {
- if (property.toString().startsWith("hibernate.")) {
- String propValue = System.getProperty(property.toString());
- result.put(property, propValue);
+ 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);
+ }
}
}
- return result;
}
}
distribution/war-zip/pom.xml 2(+1 -1)
diff --git a/distribution/war-zip/pom.xml b/distribution/war-zip/pom.xml
index d0ddb28..86f55c6 100755
--- a/distribution/war-zip/pom.xml
+++ b/distribution/war-zip/pom.xml
@@ -62,7 +62,7 @@
</execution>
</executions>
<configuration>
- <file>${project.build.directory}/unpacked/deployments/auth-server.war/WEB-INF/classes/META-INF/persistence.xml</file>
+ <file>${project.build.directory}/unpacked/deployments/auth-server.war/WEB-INF/classes/META-INF/keycloak-server.json</file>
<replacements>
<replacement>
<token>java:jboss/datasources/ExampleDS</token>
diff --git a/project-integrations/aerogear-ups/app/pom.xml b/project-integrations/aerogear-ups/app/pom.xml
index 2bf361c..eb42ab7 100755
--- a/project-integrations/aerogear-ups/app/pom.xml
+++ b/project-integrations/aerogear-ups/app/pom.xml
@@ -35,11 +35,6 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.keycloak</groupId>
- <artifactId>keycloak-as7-adapter</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
<groupId>net.iharder</groupId>
<artifactId>base64</artifactId>
</dependency>
@@ -119,4 +114,31 @@
</plugin>
</plugins>
</build>
+
+ <profiles>
+ <profile>
+ <id>as7</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>org.keycloak</groupId>
+ <artifactId>keycloak-as7-adapter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <id>wildfly</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.keycloak</groupId>
+ <artifactId>keycloak-wildfly-adapter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
</project>
diff --git a/project-integrations/aerogear-ups/app/src/main/webapp/WEB-INF/web.xml b/project-integrations/aerogear-ups/app/src/main/webapp/WEB-INF/web.xml
index 23e2831..77b633e 100755
--- a/project-integrations/aerogear-ups/app/src/main/webapp/WEB-INF/web.xml
+++ b/project-integrations/aerogear-ups/app/src/main/webapp/WEB-INF/web.xml
@@ -41,8 +41,8 @@
-->
</security-constraint>
- <login-config>
- <auth-method>BASIC</auth-method>
+ <login-config>
+ <auth-method>KEYCLOAK</auth-method>
<realm-name>demo</realm-name>
</login-config>
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 6a54eca..989a356 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
@@ -60,5 +60,12 @@
"scheduled": {
"interval": 900
+ },
+
+ "connectionsJpa": {
+ "default": {
+ "dataSource": "java:jboss/datasources/ExampleDS",
+ "databaseSchema": "update"
+ }
}
}
\ No newline at end of file
diff --git a/project-integrations/aerogear-ups/README.md b/project-integrations/aerogear-ups/README.md
index 3a490b3..780081b 100755
--- a/project-integrations/aerogear-ups/README.md
+++ b/project-integrations/aerogear-ups/README.md
@@ -1,10 +1,15 @@
Self Bootstrapping Keycloak Server and Application
==========================================================
-To get this running:
-1. Boot up JBoss EAP. (This is an EAP build!)
-2. In the project-integrations/aerogear-ups directory do:
-$ mvn clean install jboss-as:deploy
+To get this running boot up JBoss AS7, EAP or WildFly.
+
+To deploy to AS7 run:
+
+ mvn clean install jboss-as:deploy
+
+To deploy to WildFly run:
+
+ mvn -Pwildfly clean install wildfly:deploy
This is an example of bundling two wars: a keycloak server war and application WAR together so that keycloak is bootstrapped out of the
box. The structure of the example is:
project-integrations/README.md 1(+0 -1)
diff --git a/project-integrations/README.md b/project-integrations/README.md
index f9299b2..02814ee 100644
--- a/project-integrations/README.md
+++ b/project-integrations/README.md
@@ -2,4 +2,3 @@ Keycloak External Project Integrations
==========
Everthing in this directory is examples related to integration with non-keycloak projects. Its a sandbox we use to test integrations with third-party projects
-
\ 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 bc1c102..e9bf7f2 100755
--- a/server/src/main/resources/META-INF/keycloak-server.json
+++ b/server/src/main/resources/META-INF/keycloak-server.json
@@ -60,5 +60,12 @@
"scheduled": {
"interval": 900
+ },
+
+ "connectionsJpa": {
+ "default": {
+ "dataSource": "java:jboss/datasources/ExampleDS",
+ "databaseSchema": "update"
+ }
}
}
\ No newline at end of file
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 42e593d..fb18bfc 100755
--- a/testsuite/integration/src/main/resources/META-INF/keycloak-server.json
+++ b/testsuite/integration/src/main/resources/META-INF/keycloak-server.json
@@ -59,6 +59,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}",
@@ -67,5 +78,4 @@
"clearOnStartup": "${keycloak.connectionsMongo.clearOnStartup:false}"
}
}
-
}
\ No newline at end of file
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 746a87a..e0aa2be 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");
}
}
};