Simple example using keycloak and bind two spring boot services with rest api.
- Spring Boot >= 3.x
- Keycloak >= 21.x
- Java 17
- Maven >= 3.2.1
- Docker >= 3.0
Keycloak can be started as docker service by using Makefile.
# start keycloak server (admin user is admin:admin)
$ make keycloak_start
# initial setup (add user larmic:test and add user role mapping)
$ make keycloak_setup_user_and_roles
RUN SUCCESSFUL
# retrieve user larmic access token
# validate it on https://jwt.io/
$ make http_get_larmic_access_token
# stop and remove keycloak stuff
$ make keycloak_stop
# clone project
$ git clone https://github.com/larmic/spring-boot-demos
# build java application
$ make java-build-application
# start java service
$ make java-run-application
Call unsecured hello api
Call secured hello api redirects to Keycloak
Jetbrains HTTP Client
(instead of plain curl) is used. The .http scripts containing a validations (or test) phase. So
if script is ending with RUN SUCCESSFUL
everything is working fine.
# call unsecured hello api
$ make http-get-hello-unsecure
RUN SUCCESSFUL
# call secured hello api without access token
$ make http-get-hello-secure-with-token
RUN SUCCESSFUL
$ make http-get-hello-secure-without-token
RUN SUCCESSFUL