Level: Beginner Technologies: JavaEE Summary: JSP Profile Application Target Product: Keycloak, WildFly
This quickstart demonstrates how to protect a SAML Service Provider that authenticates using Keycloak. Once authenticated the application shows the users profile information.
To compile and run this quickstart you will need:
- JDK 17
- Apache Maven 3.8.6
- Wildfly 29+
- Keycloak 21+
- Docker 20+
To start a Keycloak Server you can use OpenJDK on Bare Metal, Docker, Openshift or any other option described in Keycloak Getting Started guides. For example when using Docker just run the following command in the root directory of this quickstart:
docker run --name keycloak \
-e KEYCLOAK_ADMIN=admin \
-e KEYCLOAK_ADMIN_PASSWORD=admin \
--network=host \
quay.io/keycloak/keycloak:{KC_VERSION} \
start-dev \
--http-port=8180
where KC_VERSION
should be set to 21.0.0 or higher.
You should be able to access your Keycloak Server at http://localhost:8180.
Log in as the admin user to access the Keycloak Administration Console. Username should be admin
and password admin
.
Import the realm configuration file to create a new realm called quickstart
.
For more details, see the Keycloak documentation about how to create a new realm.
In order to deploy the example application, you need a Wildfly Server up and running. For more details, see the Wildfly documentation about how to install the server.
Once you have Wildfly server downloaded somewhere, it is needed to install SAML adapter into it. It can be installed with the usage of Galleon tools. Please follow these instructions:
-
Download Galleon tools. The ZIP can be downloaded for example from this page and unzip to some location on your laptop.
-
Install Keycloak SAML adapter into Wildfly via Galleon. It can be done for instance with the command similar to this (replace environment variables according to your environment and used versions):
cd wildfly-$WILDFLY_VERSION
$GALLEON_PATH/bin/galleon.sh install org.keycloak:keycloak-saml-adapter-galleon-pack:$KC_VERSION --layers=keycloak-client-saml
There are alternative ways for doing that as described in the Wildfly SAML documentation. You can check what path suits best your needs.
- Start Wildfly server and make sure the server is accessible from
localhost
and listening on port8080
.
-
Open a terminal and navigate to the root directory of this quickstart.
-
The following shows the command to deploy the quickstart:
mvn -Djakarta clean wildfly:deploy
You can access the application with the following URL: http://localhost:8080/servlet-saml-service-provider
You should be able to authenticate using any of these users:
Username | Password | Roles |
---|---|---|
alice | alice | user |
-
Open a terminal and navigate to the root directory of this quickstart.
-
The following shows the command to undeploy the quickstart:
mvn -Djakarta install wildfly:undeploy
Make sure Keycloak is running.
You don't need Wildfly running because a temporary server is started during test execution.
-
Open a terminal and navigate to the root directory of this quickstart.
-
Run the following command to build and run tests:
mvn -Djakarta clean verify