Baeldung/spring-security-oauth

[oauth-rest/oauth-authorization-server] Keycloak realm survives restarts

dxmann73 opened this issue · 1 comments

As far as I understand it, the application is bootstrapping a complete Keycloak server from keycloak-server.json, and after that it creates the baeldung realm from baeldung-realm.json

This only works once. After I restart the application, creating the baeldung realm fails with "Couldn't create keycloak master admin user: Can't create initial user as users already exists" when creating the initial user , and subsequent errors when creating the realm.

Although when I log in, I can see the realm and its users.

The reason for this is that keycloak has actually a H2 file provider in its own settings:

"connectionsJpa": {
		"default": {
			"url": "${keycloak.connectionsJpa.url:jdbc:h2:./target/keycloak}",

while the jdbc:h2:mem:testdb setting in application.yml is not used.

I've changed this in my local fork, if you want I can provide a PR.

We fixed the config file.