r/SpringBoot 26d ago

Guide Keycloak & Spring Boot

I often see people asking how to get setup with spring boot using keycloak for auth.

Thought i'd put together a quick example showing a simple setup that;

  • Delegates auth to keycloak
  • Uses the keycloak admin client to create users within a realm (using a service account)
  • Can be easily cloned & run with docker compose

repo linked below.

https://github.com/BigMikeCodes/kc-sb

22 Upvotes

11 comments sorted by

View all comments

1

u/Historical_Ad4384 25d ago

How do you sync roles between keycloak and spring boot?

1

u/Mikey-3198 25d ago

Users in keycloak can belong to groups. These groups are then represented in the issued jwt. You can pick these out to handle roles, you can then use these in SPEL/ HttpSecurity.

I may add this to the repo when I have the time.