Skip to content
Fresh

Keycloak with Spring Boot

Back

Guides

Securing Spring Boot microservice using Keycloak and Testcontainers

Learn how to create an OAuth 2.0 Resource Server using Spring Boot, secure API endpoints with Keycloak, and test the application using the Testcontainers Keycloak module.

Java Testing with Docker

30 minutes

1

Create the project

2

Write tests

3

Run tests

« Back to all guides

Securing Spring Boot microservice using Keycloak and Testcontainers

Table of contents


Learn how to create an OAuth 2.0 Resource Server using Spring Boot, secure API endpoints with Keycloak, and test the application using the Testcontainers Keycloak module.

Time to complete30 minutes

In this guide, you'll learn how to:

  • Create an OAuth 2.0 Resource Server using Spring Boot
  • Secure API endpoints using Keycloak
  • Test the APIs using the Testcontainers Keycloak module
  • Run the application locally using the Testcontainers Keycloak module

Prerequisites

  • Java 17+
  • Maven or Gradle
  • A Docker environment supported by Testcontainers

Note

If you're new to Testcontainers, visit the Testcontainers overview to learn more about Testcontainers and the benefits of using it.

Modules

  1. Create the project Set up a Spring Boot OAuth 2.0 Resource Server with Keycloak, PostgreSQL, and Testcontainers.

  2. Write tests Test the secured Spring Boot API endpoints using Testcontainers Keycloak and PostgreSQL modules.

  3. Run tests Run your Testcontainers-based Spring Boot Keycloak integration tests and explore next steps.