Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

czetsuya/Spring-Keycloak-with-REST-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

38 Commits

Repository files navigation

License: GPL v3

Spring Project Secured with Keycloak

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

Requirements:

*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.

Running Keycloak in Docker

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

Running Keycloak as Standalone

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.

Users

Role=User, kerri / kerri Role=Admin, admin / admin

Note:

  • 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

References

Authors

  • Edward P. Legaspi - Java Architect - czetsuya

About

Securing a Spring REST API with Keycloak with bearer-only=true.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /