From 8b4bb72fb3387ba65c39f977587226970b6c1d6d Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Sat, 3 Dec 2016 13:33:16 -0500 Subject: [PATCH] enhance user storage jpa example --- examples/providers/user-storage-jpa/README.md | 22 ++++++-- examples/providers/user-storage-jpa/pom.xml | 56 ++++++++++++++++++- .../main/resources/META-INF/persistence.xml | 2 +- pom.xml | 2 +- 4 files changed, 75 insertions(+), 7 deletions(-) diff --git a/examples/providers/user-storage-jpa/README.md b/examples/providers/user-storage-jpa/README.md index 89eacad397..da0841bd3e 100755 --- a/examples/providers/user-storage-jpa/README.md +++ b/examples/providers/user-storage-jpa/README.md @@ -1,14 +1,28 @@ Example User Storage Provider with EJB and JPA =================================================== -This is an example of the User Storage SPI implemented using EJB and JPA. To deploy this provider you must have Keycloak -running in standalone or standalone-ha mode. Then type the follow maven command: +This is an example of the User Storage SPI implemented using EJB and JPA. You must first deploy the datasource it uses. +Start up the Keycloak server. Then in the directory of this example type the following maven command: + + mvn -Padd-datasource install + +You only need to execute this maven command once. If you execute this again, then you will get an error message that the datasource +already exists. + +If you open the pom.xml file you'll see that the add-datasource profile creates an XA datasource using the built +in H2 database that comes with the server. An XA datasource is required because you cannot use two non-xa datasources +in the same transaction. The Keycloak database is non-xa. + +Another thing to note is that the xa-datasource created is in-memory only. If you reboot the server, any users you've +added or changes you've made to users loaded by this provider will be wiped clean. + +To deploy the provider, run the following maven command: mvn clean install wildfly:deploy +You can run as many times as you want and the provider will be redeployed. + Login and go to the User Federation tab and you should now see your deployed provider in the add-provider list box. Add the provider, save it, then any new user you create will be stored and in the custom store you implemented. You can modify the example and hot deploy it using the above maven command again. -This example uses the built in in-memory datasource that comes with keycloak: ExampleDS. NOTE!!! You'll have -to change this to be an xa datasource for this to work. diff --git a/examples/providers/user-storage-jpa/pom.xml b/examples/providers/user-storage-jpa/pom.xml index 0eb846feb9..098b981007 100755 --- a/examples/providers/user-storage-jpa/pom.xml +++ b/examples/providers/user-storage-jpa/pom.xml @@ -75,7 +75,7 @@ 1.8 - + org.wildfly.plugins wildfly-maven-plugin @@ -84,4 +84,58 @@ + + + + add-datasource + + + + org.wildfly.plugins + wildfly-maven-plugin + + false + true + + + + add-datasource + install + + add-resource + + + +
subsystem=datasources
+ + +
xa-data-source=java:jboss/datasources/ExampleXADS
+ + java:jboss/datasources/ExampleXADS + true + h2 + + + +
+ xa-datasource-properties=URL +
+ + jdbc:h2:mem:test + +
+
+
+
+
+
+
+
+
+
+
+
+ diff --git a/examples/providers/user-storage-jpa/src/main/resources/META-INF/persistence.xml b/examples/providers/user-storage-jpa/src/main/resources/META-INF/persistence.xml index 87b5028e32..62748c8cba 100644 --- a/examples/providers/user-storage-jpa/src/main/resources/META-INF/persistence.xml +++ b/examples/providers/user-storage-jpa/src/main/resources/META-INF/persistence.xml @@ -5,7 +5,7 @@ http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> - java:jboss/datasources/KeycloakDS + java:jboss/datasources/ExampleXADS org.keycloak.examples.storage.user.UserEntity diff --git a/pom.xml b/pom.xml index 55bb4f842e..23c277d723 100755 --- a/pom.xml +++ b/pom.xml @@ -117,7 +117,7 @@ 1.0.4 1.7.2 2.3.7 - 1.0.1.Final + 1.1.0.Beta1 1.6.5