2

I have a Springboot application using embedded keycloak.

What I am looking for is a way to load the keycloak server from it, make changes to the configuration, add users and to then export this new version of keycloak.

This question got an answer on how to do a partial export but I can't find anything in the documentation of the Keycloak Admin REST API on how to do a full export.

With the standalone keycloak server I would be able to simply use the CLI and type

-Dkeycloak.migration.action=export -Dkeycloak.migration.provider=singleFile -Dkeycloak.migration.file=/tmp/keycloak-dump.json

But this is the embedded version.

This is most likely trivial since I know for a fact that newly created users have to be stored somewhere.

I added a user and restarting the application doesn't remove it, so keycloak persists it somehow. But the json files I use for keycloak server and realm setup haven't been changed.

So, with no access to a CLI without a standalone server and no REST endpoint for a full export, how do I load the server, make some changes and generate a new json via export that I can simply put into my Spring App instead?

Eric Ericson
  • 57
  • 1
  • 8

1 Answers1

4

You can make a full export with the following command (if the Springboot works with Docker containers):

[podman | docker] exec -it <pod_name> opt/jboss/keycloak/bin/standalone.sh
    -Djboss.socket.binding.port-offset=<interger_value> Docker recommend  an offset of 100 at least
    -Dkeycloak.migration.action=[export | import]
    -Dkeycloak.migration.provider=[singleFile | dir]
    -Dkeycloak.migration.dir=<DIR TO EXPORT TO> Use only iff .migration.provider=dir
    -Dkeycloak.migration.realmName=<REALM_NAME_TO_EXPORT>
    -Dkeycloak.migration.usersExportStrategy=[DIFFERENT_FILES | SKIP | REALM_FILE | SAME_FILE]
    -Dkeycloak.migration.usersPerFile=<integer_value> Use only iff .usersExportStrategy=DIFFERENT_FILES
    -Dkeycloak.migration.file=<FILE TO EXPORT TO>

I am creating an open source keycloak example with documentation; you can see a full guide about import/export in my company's GitHub.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
A.Casanova
  • 555
  • 4
  • 16