From a1b7297f257c199d01c1f5413d3e43d938ee97e4 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Thu, 2 Jan 2014 16:24:04 -0500 Subject: [PATCH] wildfly deployment structure.xml --- .../example/demo/DemoApplication.java | 5 +---- .../example/demo/DemoApplication.java | 5 +---- .../WEB-INF/jboss-deployment-structure.xml | 12 +++++++++++- integration/adapter-core/pom.xml | 2 +- integration/as7-eap6/adapter/pom.xml | 2 +- integration/servlet-oauth-client/pom.xml | 2 +- integration/undertow/pom.xml | 2 +- pom.xml | 4 ++-- .../server/KeycloakServerApplication.java | 19 ++++++++----------- .../services/managers/ApplianceBootstrap.java | 14 ++++++++++++++ .../resources/KeycloakApplication.java | 12 ++++++++++++ 11 files changed, 53 insertions(+), 26 deletions(-) diff --git a/examples/as7-eap-demo/server/src/main/java/org/keycloak/example/demo/DemoApplication.java b/examples/as7-eap-demo/server/src/main/java/org/keycloak/example/demo/DemoApplication.java index ee95beb654..df9af25a5e 100755 --- a/examples/as7-eap-demo/server/src/main/java/org/keycloak/example/demo/DemoApplication.java +++ b/examples/as7-eap-demo/server/src/main/java/org/keycloak/example/demo/DemoApplication.java @@ -1,12 +1,11 @@ package org.keycloak.example.demo; -import org.keycloak.util.JsonSerialization; import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; import org.keycloak.representations.idm.RealmRepresentation; -import org.keycloak.services.managers.ApplianceBootstrap; import org.keycloak.services.managers.RealmManager; import org.keycloak.services.resources.KeycloakApplication; +import org.keycloak.util.JsonSerialization; import javax.servlet.ServletContext; import javax.ws.rs.core.Context; @@ -22,8 +21,6 @@ public class DemoApplication extends KeycloakApplication { super(servletContext); KeycloakSession session = factory.createSession(); session.getTransaction().begin(); - ApplianceBootstrap bootstrap = new ApplianceBootstrap(); - bootstrap.bootstrap(session); install(new RealmManager(session)); session.getTransaction().commit(); } diff --git a/examples/wildfly-demo/server/src/main/java/org/keycloak/example/demo/DemoApplication.java b/examples/wildfly-demo/server/src/main/java/org/keycloak/example/demo/DemoApplication.java index ee95beb654..df9af25a5e 100755 --- a/examples/wildfly-demo/server/src/main/java/org/keycloak/example/demo/DemoApplication.java +++ b/examples/wildfly-demo/server/src/main/java/org/keycloak/example/demo/DemoApplication.java @@ -1,12 +1,11 @@ package org.keycloak.example.demo; -import org.keycloak.util.JsonSerialization; import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; import org.keycloak.representations.idm.RealmRepresentation; -import org.keycloak.services.managers.ApplianceBootstrap; import org.keycloak.services.managers.RealmManager; import org.keycloak.services.resources.KeycloakApplication; +import org.keycloak.util.JsonSerialization; import javax.servlet.ServletContext; import javax.ws.rs.core.Context; @@ -22,8 +21,6 @@ public class DemoApplication extends KeycloakApplication { super(servletContext); KeycloakSession session = factory.createSession(); session.getTransaction().begin(); - ApplianceBootstrap bootstrap = new ApplianceBootstrap(); - bootstrap.bootstrap(session); install(new RealmManager(session)); session.getTransaction().commit(); } diff --git a/examples/wildfly-demo/server/src/main/webapp/WEB-INF/jboss-deployment-structure.xml b/examples/wildfly-demo/server/src/main/webapp/WEB-INF/jboss-deployment-structure.xml index 2654f310d6..07f3c5d212 100755 --- a/examples/wildfly-demo/server/src/main/webapp/WEB-INF/jboss-deployment-structure.xml +++ b/examples/wildfly-demo/server/src/main/webapp/WEB-INF/jboss-deployment-structure.xml @@ -1,20 +1,30 @@ + + + - + + + + diff --git a/integration/adapter-core/pom.xml b/integration/adapter-core/pom.xml index 23d91149cd..0c720d8b3e 100755 --- a/integration/adapter-core/pom.xml +++ b/integration/adapter-core/pom.xml @@ -42,7 +42,7 @@ org.apache.httpcomponents httpclient - 4.1.2 + ${apache.httpcomponents.version} provided diff --git a/integration/as7-eap6/adapter/pom.xml b/integration/as7-eap6/adapter/pom.xml index 34a0ef9e71..5e2b9d595f 100755 --- a/integration/as7-eap6/adapter/pom.xml +++ b/integration/as7-eap6/adapter/pom.xml @@ -32,7 +32,7 @@ org.apache.httpcomponents httpclient - 4.1.2 + ${apache.httpcomponents.version} org.bouncycastle diff --git a/integration/servlet-oauth-client/pom.xml b/integration/servlet-oauth-client/pom.xml index 038f1aba83..c41777c733 100755 --- a/integration/servlet-oauth-client/pom.xml +++ b/integration/servlet-oauth-client/pom.xml @@ -30,7 +30,7 @@ org.apache.httpcomponents httpclient - 4.1.2 + ${apache.httpcomponents.version} org.codehaus.jackson diff --git a/integration/undertow/pom.xml b/integration/undertow/pom.xml index f3ae801d00..3cda86eea3 100755 --- a/integration/undertow/pom.xml +++ b/integration/undertow/pom.xml @@ -32,7 +32,7 @@ org.apache.httpcomponents httpclient - 4.1.2 + ${apache.httpcomponents.version} org.bouncycastle diff --git a/pom.xml b/pom.xml index d65c2ab2d8..c4b697879c 100755 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ pom + 4.1.2 3.0.5.Final 1.0.0.Beta28 2.5.0.Beta6 @@ -327,12 +328,11 @@ mysql-connector-java ${mysql.version} - diff --git a/server/src/main/java/org/keycloak/server/KeycloakServerApplication.java b/server/src/main/java/org/keycloak/server/KeycloakServerApplication.java index 4ebcae1c5f..1b430d0f9a 100755 --- a/server/src/main/java/org/keycloak/server/KeycloakServerApplication.java +++ b/server/src/main/java/org/keycloak/server/KeycloakServerApplication.java @@ -1,13 +1,12 @@ package org.keycloak.server; import org.jboss.resteasy.logging.Logger; -import org.keycloak.util.JsonSerialization; -import org.keycloak.representations.idm.RealmRepresentation; -import org.keycloak.services.managers.ApplianceBootstrap; -import org.keycloak.services.managers.RealmManager; import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; +import org.keycloak.representations.idm.RealmRepresentation; +import org.keycloak.services.managers.RealmManager; import org.keycloak.services.resources.KeycloakApplication; +import org.keycloak.util.JsonSerialization; import javax.servlet.ServletContext; import javax.ws.rs.core.Context; @@ -22,21 +21,19 @@ public class KeycloakServerApplication extends KeycloakApplication { public KeycloakServerApplication(@Context ServletContext servletContext) throws FileNotFoundException { super(servletContext); - KeycloakSession session = factory.createSession(); - session.getTransaction().begin(); - ApplianceBootstrap bootstrap = new ApplianceBootstrap(); - bootstrap.bootstrap(session); String importRealm = System.getProperty("keycloak.import"); if (importRealm != null) { + KeycloakSession session = factory.createSession(); + session.getTransaction().begin(); RealmRepresentation rep = loadJson(new FileInputStream(importRealm), RealmRepresentation.class); importRealm(session, rep); + session.getTransaction().commit(); } - session.getTransaction().commit(); } - public void importRealm(KeycloakSession session, RealmRepresentation rep ) { + public void importRealm(KeycloakSession session, RealmRepresentation rep) { try { RealmManager manager = new RealmManager(session); @@ -62,7 +59,7 @@ public class KeycloakServerApplication extends KeycloakApplication { private static T loadJson(InputStream is, Class type) { try { - return JsonSerialization.readValue(is, type); + return JsonSerialization.readValue(is, type); } catch (IOException e) { throw new RuntimeException("Failed to parse json", e); } diff --git a/services/src/main/java/org/keycloak/services/managers/ApplianceBootstrap.java b/services/src/main/java/org/keycloak/services/managers/ApplianceBootstrap.java index 3fe1453b12..f62f28c851 100755 --- a/services/src/main/java/org/keycloak/services/managers/ApplianceBootstrap.java +++ b/services/src/main/java/org/keycloak/services/managers/ApplianceBootstrap.java @@ -4,6 +4,7 @@ import org.jboss.resteasy.logging.Logger; import org.keycloak.models.ApplicationModel; import org.keycloak.models.Constants; import org.keycloak.models.KeycloakSession; +import org.keycloak.models.KeycloakSessionFactory; import org.keycloak.models.RealmModel; import org.keycloak.models.RoleModel; import org.keycloak.models.UserCredentialModel; @@ -20,6 +21,19 @@ public class ApplianceBootstrap { private static final Logger logger = Logger.getLogger(ApplianceBootstrap.class); + public void bootstrap(KeycloakSessionFactory factory) { + KeycloakSession session = factory.createSession(); + session.getTransaction().begin(); + + try { + bootstrap(session); + session.getTransaction().commit(); + } finally { + session.close(); + } + + } + public void bootstrap(KeycloakSession session) { if (session.getRealm(Constants.ADMIN_REALM) != null) { return; diff --git a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java index 93682c4e0d..9e63dac201 100755 --- a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java +++ b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java @@ -2,8 +2,13 @@ package org.keycloak.services.resources; import org.jboss.resteasy.logging.Logger; import org.keycloak.SkeletonKeyContextResolver; +import org.keycloak.models.Constants; +import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSessionFactory; import org.keycloak.models.ModelProvider; +import org.keycloak.models.UserModel; +import org.keycloak.services.managers.ApplianceBootstrap; +import org.keycloak.services.managers.RealmManager; import org.keycloak.services.managers.SocialRequestManager; import org.keycloak.services.managers.TokenManager; @@ -43,8 +48,15 @@ public class KeycloakApplication extends Application { singletons.add(new SocialResource(tokenManager, new SocialRequestManager())); classes.add(SkeletonKeyContextResolver.class); classes.add(QRCodeResource.class); + + setupDefaultRealm(); } + protected void setupDefaultRealm() { + new ApplianceBootstrap().bootstrap(factory); + } + + public static KeycloakSessionFactory createSessionFactory() { ServiceLoader providers = ServiceLoader.load(ModelProvider.class); String configuredProvider = System.getProperty(MODEL_PROVIDER);