Skip to content

Commit bd9dc07

Browse files
feat(spring-keycloak-example): added 'default' configuration, also OpenId Connect based authentication, README updated
1 parent 643dbb3 commit bd9dc07

File tree

15 files changed

+6207
-21
lines changed

15 files changed

+6207
-21
lines changed

spring-keycloak-example/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ COPY --from=extract build/target/extracted/spring-boot-loader/ ./
4242
COPY --from=extract build/target/extracted/snapshot-dependencies/ ./
4343
COPY --from=extract build/target/extracted/application/ ./
4444

45-
EXPOSE 80
45+
EXPOSE 8083
4646

4747
ENTRYPOINT [ "java", "org.springframework.boot.loader.launch.JarLauncher" ]

spring-keycloak-example/README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,28 @@ Includes a minimal setup for running a Spring Boot application secured by Keyclo
1919

2020
## Authentication Types Implemented
2121

22-
- nothing
22+
### OIDC (OpenID Connect) via Keycloak
23+
24+
- **Description:** Authentication using Keycloak as the OpenID Connect (OIDC) identity provider.
25+
26+
- **Spring Profile:** `OIDC`
27+
28+
- **Backup keycloak:** `oidc_auth_db_backup.sql`
29+
30+
- **User Credentials:**
31+
- Username: `oidc-user`
32+
- Password: `oidc-password`
33+
34+
- **Protected Route:** `/secured`
35+
36+
- **Realm:** `redirect-login-example`
37+
2338

2439
---
2540

2641
## Related Resources
2742

28-
| Description | Link |
29-
|---------------------------------|-----------------------------------------------------------------------|
30-
| Running Keycloak in a container | [keycloak.org/containers](https://www.keycloak.org/server/containers) |
43+
| Description | Link |
44+
|---------------------------------------|-------------------------------------------------------------------------|
45+
| Running Keycloak in a container | [keycloak.org/containers](https://www.keycloak.org/server/containers) |
46+
| teaching how to set up Openid connect | [youtube/IW15Q68V50E](https://youtu.be/IW15Q68V50E?si=sJjvFoq8m0xL8xLn) |

spring-keycloak-example/compose.yaml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11

22
services:
33

4+
#Not usable
45
app:
56
container_name: app
67
build:
78
context: .
89
dockerfile: Dockerfile
910
environment:
10-
SERVER_PORT: 80
11+
SERVER_PORT: 8083
1112
SPRING_PROFILES_ACTIVE: "default"
13+
AUTH_CLIENT_ID: oidc-client
14+
AUTH_CLIENT_SECRET: pvRQkTKcE2zZw9vxT30oXC1Zynq2b3yw
15+
AUTH_SCOPE: openid, profile, email
16+
AUTH_GRANT_TYPE: authorization_code
17+
AUTH_REDIRECT_URI: "{baseUrl}/login/oauth2/code/{registrationId}"
18+
AUTH_ISSUER_URI: http://keycloak:8080/realms/redirect-login-example
1219
ports:
13-
- "80:80"
20+
- "8083:8083"
1421
depends_on:
1522
- keycloak
23+
- keycloak-database
1624

1725
keycloak:
1826
container_name: keycloak
@@ -22,7 +30,10 @@ services:
2230
ports:
2331
- "8080:8080"
2432
environment:
25-
KC_DB: dev-file
33+
KC_DB: postgres
34+
KC_DB_URL: jdbc:postgresql://keycloak-database:5432/oidc_auth_db
35+
KC_DB_USERNAME: postgres
36+
KC_DB_PASSWORD: password
2637
KC_HTTP_ENABLED: "true"
2738
KC_HTTP_PORT: "8080"
2839
KC_HOSTNAME: localhost
@@ -33,4 +44,17 @@ services:
3344
KC_HTTPS_CERTIFICATE_FILE: /opt/keycloak/certs/tls.crt
3445
KC_HTTPS_CERTIFICATE_KEY_FILE: /opt/keycloak/certs/tls.key
3546
volumes:
36-
- ./docker/keycloak:/opt/keycloak/certs
47+
- ./docker/keycloak/certs:/opt/keycloak/certs
48+
depends_on:
49+
- keycloak-database
50+
51+
keycloak-database:
52+
image: postgres:14.18-alpine3.22
53+
container_name: keycloak-database
54+
environment:
55+
POSTGRES_USER: postgres #⚠️ DO NOT USE IN PRODUCTION
56+
POSTGRES_PASSWORD: password #⚠️ DO NOT USE IN PRODUCTION
57+
ports:
58+
- "5432:5432"
59+
volumes:
60+
- ./docker/keycloak/backups/oidc_auth_db_backup.sql:/docker-entrypoint-initdb.d/init.sql

0 commit comments

Comments
 (0)