Skip to content

How to fallback basic authentication credentials to oauth2

In the past version of Keycloak, RedHat was providing an adapter that was pretty straight forward to link your spring boot application with Keycloak. Since the latest versions, the adapter has been deprecated. As Keycloak sticks with OAuth2 standards, you simply can use the spring-security-starter.

xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-oauth2-resource-server</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-oauth2-jose</artifactId>
</dependency>

However, the Keycloak adapter was also offering a feature that is not available anymore out of the box.

yaml
keycloak:
  enabled: true
  enable-basic-auth: true

The keycloak.enable-basic-auth feature provide a way to handle basic authentication within your application, and delegate it to a Keycloak server in a seamless manner.