Skip to content

Commit

Permalink
Added Keycloak docker compose files
Browse files Browse the repository at this point in the history
  • Loading branch information
stojsavljevic committed Dec 21, 2023
1 parent 3d68238 commit 6108bbc
Show file tree
Hide file tree
Showing 7 changed files with 2,285 additions and 27 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
## Spring Boot Security OAuth2 Example Application ![build status](https://github.com/stojsavljevic/spring-security-oauth2/actions/workflows/maven.yml/badge.svg)
# Spring Boot Security OAuth2 Example Application ![build status](https://github.com/stojsavljevic/spring-security-oauth2/actions/workflows/maven.yml/badge.svg)

This example showcases Spring Security 6 OAuth2 configuration for both the client and resource server.

Demonstrates Spring Security 6 OAuth2 configuration for client and resource server.
## Getting Started

To begin, utilize Keycloak for authentication. The recommended starting point is to build the Keycloak image using `docker-compose` and the `docker-compose.yaml` file within the `keycloak` directory. Once the image is built, start it. It will automatically import the `SpringBootKeycloak` realm from `realm-import.json`, which includes the `oauth2-client` client and the user `user/user`. Keycloak is available on port 8080, administrator credentials are `admin/admin`.

Uses Keycloak (or GitHub) for authentication. Make sure that Keycloak is properly configured (realm, client, users, roles...). Client needs to have Service Accounts Enabled for client credentials flow.
If you prefer to use a different Keycloak instance, ensure that Keycloak is correctly configured with the necessary realms, clients, users, and roles. The client must have Service Accounts Enabled for the client credentials flow. Adjust the `application.yaml` in both modules according to your specific settings.

## Usage

Configured using Spring Security properties.
The `spring-security-oauth2-client` module communicates with the `spring-security-oauth2-resource-server` to retrieve the username. Refer to [spring-security-oauth2-client/README.md](spring-security-oauth2-client/README.md) for a list of endpoints that demonstrate various authentication mechanisms.


`spring-security-oauth2-client` calls `spring-security-oauth2-resource-server` to get username from it.


Before using application configure `application.yaml` in both modules.
15 changes: 15 additions & 0 deletions keycloak/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'
services:
keycloak:
image: quay.io/keycloak/keycloak:23.0.1
command:
- "start-dev"
- "--import-realm"
ports:
- "8080:8080"
volumes:
- ./realm-import.json:/opt/keycloak/data/import/realm-import.json
environment:
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
KEYCLOAK_IMPORT: /opt/keycloak/data/import/realm-import.json
Loading

0 comments on commit 6108bbc

Please sign in to comment.