Skip to content

feat: add keycloak dev service#167

Open
jimisola wants to merge 4 commits intoarconia-io:mainfrom
jimisola:feeature/keycloak
Open

feat: add keycloak dev service#167
jimisola wants to merge 4 commits intoarconia-io:mainfrom
jimisola:feeature/keycloak

Conversation

@jimisola
Copy link
Copy Markdown
Contributor

Description

NOTE: This PR brought me into somewhat uncharted territory with regards to the lifecycle (or rather startup sequence) of Spring Boot. So, the implementation seem to work but it is the right way? And if so, there is a little more to be done in terms of testing, injection properties etc.

Introduce the first implementation of Keycloak dev-services: a registrar-based startup that registers a KeycloakContainer bean definition early, starts the container during bean-factory post-processing, publishes derived properties into the Environment, registers the running instance as a singleton with proper shutdown handling, and integrates with Spring Boot ServiceConnection.

Key details

  • Add sKeycloakContainerRegistrar to register the KeycloakContainer bean definition and to create/start the container during postProcessBeanFactory(...).
  • Adds KeycloakDevServicesAutoConfiguration to expose the registrar and a delegating @ServiceConnection("keycloak") bean so ServiceConnection and ConnectionDetails infra can find the running container.

Why

  • Provide early type/definition visibility while starting the container when BeanFactory and binding APIs are available.
  • Expose the running container for DI, DevTools restart scope metadata, and Spring Boot ServiceConnection integration.

Left:

  1. I think it would be useful to not only use ApplicationContextListener but to have a full SpringBootTest with a application.yml file for a particular test case to confirm that:

a) implementation works with application.yml files
b) @Serviceconnection works (it's circumvented with context.getBeanFactory().getBeanNamesForType(KeycloakContainer.class))
c) property injection works properly

  1. Investigate if more properties need to be injected per default:

See: Common Application Properties

a) Currently only, spring.security.oauth2.resourceserver.jwt.issuer-uri is injected, but there are numerous Security Properties that can be set, especially uris for things such as logout, revocation, OAuth 2 etc.

b) Spring Security client refers to a provider but we don't know the name of it. I think that we should allow for a default such as: spring.security.oauth2.client.provider.keycloak.issuer-uri

but also allow the user to add additional clients that needs to have issuer-uri injected (so, that it's plug-n-play with the users current configuration).

Fixes #47

Checklist

Signed-off-by: Jimisola Laursen <jimisola@jimisola.com>
…ontainerRegistrar for improved configuration

Signed-off-by: Jimisola Laursen <jimisola@jimisola.com>
@jimisola jimisola changed the title Feeature/keycloak feat: add keycloak dev service Jan 25, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Feb 9, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Dev Services] Add Keycloak Dev Service

1 participant