*Help me keep this project updated by supporting me on Patreon.
A demo project created to demonstrate how a Spring project can be secured using a Keycloak server via bearer token.
SpringDoc URLs:
- springdoc.api-docs=/api-docs
- springdoc.swagger-ui.path=/swagger-ui.html
- Keycloak server 10.0.1
- https://github.com/czetsuya/keycloak-react
*In case you will be using Keycloak version greater than 7.0.0, the Keycloak team has introduced the notion of feature and uploading the json file has become one of them. Sadly, it is disabled by default. To enable realm, upload run Keycloak with the given parameter:
standalone.bat -Djboss.socket.binding.port-offset=1 -Dkeycloak.profile.feature.upload_scripts=enabled
Here's the documentation: https://www.keycloak.org/docs/latest/server_installation/, look at the profiles section.
To run Keycloak as a docker container and enable the realm configuration upload, the keycloak.profile.feature.upload_scripts must be set.
docker run --name=keycloak10 -d -p 8080:8080 -e JAVA_OPTS="-Dkeycloak.profile.feature.scripts=enabled -Dkeycloak.profile.feature.upload_scripts=enabled" -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=kerri jboss/keycloak
Import the realm file inside the config folder. If you're not familiar with the installation process, visit the blog I have written in the reference section below.
When you import the realm it will also create the users below.
Role=User, kerri / kerri Role=Admin, admin / admin
- Make sure that you have the same Keycloak client credentials value for the 2 project ands Keycloak server.
If keycloak.json file is to be used instead of application.yml, set the following system variable and make sure that you have the file keycloak.json in src/main/resources.
keycloak.configurationFile = classpath:keycloak.json
- https://czetsuya-tech.blogspot.com/2020/02/download-and-configure-keycloak-sso-server.html
- https://github.com/springdoc/springdoc-openapi-maven-plugin
- Edward P. Legaspi - Java Architect - czetsuya