Skip to content

Instantly share code, notes, and snippets.

@gastaldi
Last active May 26, 2022 19:10
Show Gist options
  • Save gastaldi/6d86b71f9a8ba117adb3f7a38d286abb to your computer and use it in GitHub Desktop.
Save gastaldi/6d86b71f9a8ba117adb3f7a38d286abb to your computer and use it in GitHub Desktop.
JBoss Forge Script to create a WildFly Swarm Microservice and configuring as a KeyCloak client
#Install the required plugins
addon-install-from-git --url https://github.com/forge/wildfly-swarm-addon.git
addon-install-from-git --url https://github.com/forge/keycloak-addon.git
# Create the project and configure the WildFly Swarm maven plugin
project-new --named demo --stack JAVA_EE_7 --type wildfly-swarm
# Create the JPA entity
jpa-new-entity --named Customer
# Add some fields to the JPA entity
jpa-new-field --named firstName
jpa-new-field --named lastName
# Create the REST endpoint for the entity
rest-generate-endpoints-from-entities --targets org.demo.model.Customer
# Since we are running from a microservice, we need to enable CORS - Cross Origin Resource Sharing
rest-new-cross-origin-resource-sharing-filter
# Detect and add the missing fractions to the build descriptor (will build the project first)
wildfly-swarm-detect-fractions --build --depend
# Create a main class for custom Swarm configuration
wildfly-swarm-new-main-class
# Configure KeyCloak authentication
wildfly-swarm-add-fraction --fractions keycloak
security-add-login-config --auth-method KEYCLOAK --security-realm master
security-add-constraint --web-resource-name Customer --url-patterns /rest/customers --security-roles user
# Install the keycloak.json file to WEB-INF
keycloak-install-client-json --server-url http://localhost:9000/auth --realm master --client-id security-admin-console --user admin --password admin
# Copy the import.sql file to src/main/resources
echo TODO: Create an import.sql file in src/main/resources to have some example data
@gastaldi
Copy link
Author

gastaldi commented Jun 15, 2016

You need a Keycloak server running on port 9000 and make sure that the Direct Access Grants Enabled option is is enabled for this client

java -Dswarm.http.port=9000 -jar keycloak-swarm.jar

Download the JAR here: http://central.maven.org/maven2/org/wildfly/swarm/servers/keycloak/1.0.0.CR1/keycloak-1.0.0.CR1-swarm.jar

@gastaldi
Copy link
Author

To run this script, save this file somewhere in your computer, start Forge (you can download in http://forge.jboss.org/download) and execute:

run microservice.fsh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment