This project shows an example integration of Spring Boot with Keycloak.
- JDK 17+ (How to install OpenJDK 17 on Ubuntu)
- Maven (or you can use
mvnw
provided in the project) - Docker (A configuration similar to the one used in this project is described in Keycloak in Docker #1 – How to run Keycloak in a Docker container , Keycloak in Docker #2 – How to import a Keycloak realm) and Keycloak in Docker #5 – How to export a realm with users and secrets) .
First, clone this repository.
Then, build it locally with:
mvn clean install
You can run the app in a command line with the following command:
mvn spring-boot:run
You can run tests with:
mvn test
Run the keycloak
service with the following commands:
cd docker
docker compose up -d
Below you'll find a list of default user accounts.
- username:
keycloak
- password:
keycloak
- usernames:
christina
,hanna
,carlo
,noel
- password:
test
- realm role:
user
- Visit the http://localhost:8024/auth url. Select the
Administration Console
option and log in as the Keycloak admin [keycloak:keycloak
]. - As an admin you can see all users associated with the
keep-growing
realm by clicking theView all users
button on the http://localhost:8024/auth/admin/master/console/#/realms/keep-growing/users page. - What's more, you can log in as any user associated with the
keep-growing
realm by clicking theSign in
button on the http://localhost:8024/auth/realms/keep-growing/account page.
Swagger UI is available at http://localhost:8080/swagger-ui.html.
The Keycloak client details are available in the application.properties
file:
- client_id:
spring-boot-example-app
- client_secret:
QjLCjk1I9sugcZSDFCsyAkoLOqAHDLKC
http://localhost:8080/v3/api-docs
The Postman collection for the API is publicly available1, click the button below and select the localhost
environment:
The authorization config used in the collection is described in the Kecloak in Docker #7 – How to authorize requests via Postman post
- Spring Boot v2.7+
- OpenJDK 17, Maven
- Keycloak, jboss/keycloak Docker image, Keycloak Spring Boot adapter
- springdoc-openapi
- Docker Compose
- Dummy4j
Footnotes
-
Clicking the
Run in Postman
button navigates to the page where you can fork the collection to your workspace. Forking the collection into your workspace will enable you to contribute to the source collection using pull requests. You can also view the collection in a public workspace if you like and even import a copy of the collection using the links present on the screen. ↩