wildfly deployment structure.xml

This commit is contained in:
Bill Burke 2014-01-02 16:24:04 -05:00
parent e393a347cc
commit a1b7297f25
11 changed files with 53 additions and 26 deletions

View file

@ -1,12 +1,11 @@
package org.keycloak.example.demo; package org.keycloak.example.demo;
import org.keycloak.util.JsonSerialization;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.services.managers.ApplianceBootstrap;
import org.keycloak.services.managers.RealmManager; import org.keycloak.services.managers.RealmManager;
import org.keycloak.services.resources.KeycloakApplication; import org.keycloak.services.resources.KeycloakApplication;
import org.keycloak.util.JsonSerialization;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
@ -22,8 +21,6 @@ public class DemoApplication extends KeycloakApplication {
super(servletContext); super(servletContext);
KeycloakSession session = factory.createSession(); KeycloakSession session = factory.createSession();
session.getTransaction().begin(); session.getTransaction().begin();
ApplianceBootstrap bootstrap = new ApplianceBootstrap();
bootstrap.bootstrap(session);
install(new RealmManager(session)); install(new RealmManager(session));
session.getTransaction().commit(); session.getTransaction().commit();
} }

View file

@ -1,12 +1,11 @@
package org.keycloak.example.demo; package org.keycloak.example.demo;
import org.keycloak.util.JsonSerialization;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.services.managers.ApplianceBootstrap;
import org.keycloak.services.managers.RealmManager; import org.keycloak.services.managers.RealmManager;
import org.keycloak.services.resources.KeycloakApplication; import org.keycloak.services.resources.KeycloakApplication;
import org.keycloak.util.JsonSerialization;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
@ -22,8 +21,6 @@ public class DemoApplication extends KeycloakApplication {
super(servletContext); super(servletContext);
KeycloakSession session = factory.createSession(); KeycloakSession session = factory.createSession();
session.getTransaction().begin(); session.getTransaction().begin();
ApplianceBootstrap bootstrap = new ApplianceBootstrap();
bootstrap.bootstrap(session);
install(new RealmManager(session)); install(new RealmManager(session));
session.getTransaction().commit(); session.getTransaction().commit();
} }

View file

@ -1,20 +1,30 @@
<jboss-deployment-structure> <jboss-deployment-structure>
<deployment> <deployment>
<!--
<exclude-subsystems>
<subsystem name="jaxrs" />
</exclude-subsystems>
-->
<exclusions> <exclusions>
<!-- Exclude Version cxf of JBOSS --> <!-- Exclude Version cxf of JBOSS -->
<module name="org.apache.cxf" /> <module name="org.apache.cxf" />
<!-- Exclude JAVA EE of JBOSS (javax.ws..) => Add dependency javax.annotation --> <!-- Exclude JAVA EE of JBOSS (javax.ws..) => Add dependency javax.annotation -->
<module name="javaee.api" /> <module name="javaee.api" />
<module name="javax.ws.rs.api"/>
<!-- Exclude RestEasy conflict (javax.ws.rs.ext.RunDelegate) --> <!-- Exclude RestEasy conflict (javax.ws.rs.ext.RunDelegate) -->
<module name="org.codehaus.jackson.jackson-core-asl" />
<module name="org.jboss.resteasy.resteasy-atom-provider" /> <module name="org.jboss.resteasy.resteasy-atom-provider" />
<module name="org.jboss.resteasy.resteasy-cdi" /> <module name="org.jboss.resteasy.resteasy-cdi" />
<module name="org.jboss.resteasy.resteasy-jackson-provider" /> <module name="org.jboss.resteasy.resteasy-crypto" />
<module name="org.jboss.resteasy.resteasy-jaxb-provider" /> <module name="org.jboss.resteasy.resteasy-jaxb-provider" />
<module name="org.jboss.resteasy.resteasy-jaxrs" /> <module name="org.jboss.resteasy.resteasy-jaxrs" />
<module name="org.jboss.resteasy.resteasy-jackson-provider" />
<module name="org.jboss.resteasy.resteasy-jettison-provider" /> <module name="org.jboss.resteasy.resteasy-jettison-provider" />
<module name="org.jboss.resteasy.resteasy-json-p-provider" />
<module name="org.jboss.resteasy.resteasy-jsapi" /> <module name="org.jboss.resteasy.resteasy-jsapi" />
<module name="org.jboss.resteasy.resteasy-multipart-provider" /> <module name="org.jboss.resteasy.resteasy-multipart-provider" />
<module name="org.jboss.resteasy.resteasy-validator-provider-11" />
<module name="org.jboss.resteasy.resteasy-yaml-provider" /> <module name="org.jboss.resteasy.resteasy-yaml-provider" />
</exclusions> </exclusions>
</deployment> </deployment>

View file

@ -42,7 +42,7 @@
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>4.1.2</version> <version>${apache.httpcomponents.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -32,7 +32,7 @@
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>4.1.2</version> <version>${apache.httpcomponents.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.bouncycastle</groupId> <groupId>org.bouncycastle</groupId>

View file

@ -30,7 +30,7 @@
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>4.1.2</version> <version>${apache.httpcomponents.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.codehaus.jackson</groupId> <groupId>org.codehaus.jackson</groupId>

View file

@ -32,7 +32,7 @@
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>4.1.2</version> <version>${apache.httpcomponents.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.bouncycastle</groupId> <groupId>org.bouncycastle</groupId>

View file

@ -12,6 +12,7 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<properties> <properties>
<apache.httpcomponents.version>4.1.2</apache.httpcomponents.version>
<resteasy.version>3.0.5.Final</resteasy.version> <resteasy.version>3.0.5.Final</resteasy.version>
<undertow.version>1.0.0.Beta28</undertow.version> <undertow.version>1.0.0.Beta28</undertow.version>
<picketlink.version>2.5.0.Beta6</picketlink.version> <picketlink.version>2.5.0.Beta6</picketlink.version>
@ -327,12 +328,11 @@
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version> <version>${mysql.version}</version>
</dependency> </dependency>
<!-- Keep this at 4.1.2 to make sure we're compatible with AS7 -->
<!-- the dependency seems to override Resteasy 3.0.5's dependeing on 4.2.1 <!-- the dependency seems to override Resteasy 3.0.5's dependeing on 4.2.1
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>4.1.2</version> <version>${apache.httpcomponents.version}</version>
</dependency> </dependency>
--> -->
</dependencies> </dependencies>

View file

@ -1,13 +1,12 @@
package org.keycloak.server; package org.keycloak.server;
import org.jboss.resteasy.logging.Logger; 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.KeycloakSession;
import org.keycloak.models.RealmModel; 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.services.resources.KeycloakApplication;
import org.keycloak.util.JsonSerialization;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
@ -22,21 +21,19 @@ public class KeycloakServerApplication extends KeycloakApplication {
public KeycloakServerApplication(@Context ServletContext servletContext) throws FileNotFoundException { public KeycloakServerApplication(@Context ServletContext servletContext) throws FileNotFoundException {
super(servletContext); super(servletContext);
KeycloakSession session = factory.createSession();
session.getTransaction().begin();
ApplianceBootstrap bootstrap = new ApplianceBootstrap();
bootstrap.bootstrap(session);
String importRealm = System.getProperty("keycloak.import"); String importRealm = System.getProperty("keycloak.import");
if (importRealm != null) { if (importRealm != null) {
KeycloakSession session = factory.createSession();
session.getTransaction().begin();
RealmRepresentation rep = loadJson(new FileInputStream(importRealm), RealmRepresentation.class); RealmRepresentation rep = loadJson(new FileInputStream(importRealm), RealmRepresentation.class);
importRealm(session, rep); importRealm(session, rep);
session.getTransaction().commit();
} }
session.getTransaction().commit();
} }
public void importRealm(KeycloakSession session, RealmRepresentation rep ) { public void importRealm(KeycloakSession session, RealmRepresentation rep) {
try { try {
RealmManager manager = new RealmManager(session); RealmManager manager = new RealmManager(session);
@ -62,7 +59,7 @@ public class KeycloakServerApplication extends KeycloakApplication {
private static <T> T loadJson(InputStream is, Class<T> type) { private static <T> T loadJson(InputStream is, Class<T> type) {
try { try {
return JsonSerialization.readValue(is, type); return JsonSerialization.readValue(is, type);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Failed to parse json", e); throw new RuntimeException("Failed to parse json", e);
} }

View file

@ -4,6 +4,7 @@ import org.jboss.resteasy.logging.Logger;
import org.keycloak.models.ApplicationModel; import org.keycloak.models.ApplicationModel;
import org.keycloak.models.Constants; import org.keycloak.models.Constants;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel; import org.keycloak.models.RoleModel;
import org.keycloak.models.UserCredentialModel; import org.keycloak.models.UserCredentialModel;
@ -20,6 +21,19 @@ public class ApplianceBootstrap {
private static final Logger logger = Logger.getLogger(ApplianceBootstrap.class); 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) { public void bootstrap(KeycloakSession session) {
if (session.getRealm(Constants.ADMIN_REALM) != null) { if (session.getRealm(Constants.ADMIN_REALM) != null) {
return; return;

View file

@ -2,8 +2,13 @@ package org.keycloak.services.resources;
import org.jboss.resteasy.logging.Logger; import org.jboss.resteasy.logging.Logger;
import org.keycloak.SkeletonKeyContextResolver; import org.keycloak.SkeletonKeyContextResolver;
import org.keycloak.models.Constants;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory; import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.models.ModelProvider; 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.SocialRequestManager;
import org.keycloak.services.managers.TokenManager; import org.keycloak.services.managers.TokenManager;
@ -43,8 +48,15 @@ public class KeycloakApplication extends Application {
singletons.add(new SocialResource(tokenManager, new SocialRequestManager())); singletons.add(new SocialResource(tokenManager, new SocialRequestManager()));
classes.add(SkeletonKeyContextResolver.class); classes.add(SkeletonKeyContextResolver.class);
classes.add(QRCodeResource.class); classes.add(QRCodeResource.class);
setupDefaultRealm();
} }
protected void setupDefaultRealm() {
new ApplianceBootstrap().bootstrap(factory);
}
public static KeycloakSessionFactory createSessionFactory() { public static KeycloakSessionFactory createSessionFactory() {
ServiceLoader<ModelProvider> providers = ServiceLoader.load(ModelProvider.class); ServiceLoader<ModelProvider> providers = ServiceLoader.load(ModelProvider.class);
String configuredProvider = System.getProperty(MODEL_PROVIDER); String configuredProvider = System.getProperty(MODEL_PROVIDER);