How To Secure Your Spring Apps With Keycloak: Thomas Darimont
How To Secure Your Spring Apps With Keycloak: Thomas Darimont
Thomas Darimont
@thomasdarimont
Thomas Darimont
• Fellow
• Spring Data Team Alumni
• Open Source Enthusiast
• Organizer Java User Group Saarland
• Keycloak Contributor for over 3 years
The Journey
• Keycloak
• Single Sign-on
• Securing Applications
• Keycloak in the field
Keycloak
Overview
Project
Admin Console
● Angular JS (1.6.x)
● PatternFly
● Bootstrap
Keycloak Server
● Wildfly 15.0.x
● JAX-RS (Resteasy)
● JPA (Hibernate)
● Infinispan (JGroups)
● Freemarker
● Jackson 2.x
● JBoss Logging
● Apache Directory API
● Commons HTTP Client
Server Architecture
Admin Account Login
INFO Account ODIC SAML
Console Frontend Frontend
REST API
Admin
Protocol Mapper
Realm
Keycloak2
2
Keycloak
Admin
Infinispan
Client
Infinispan
Keycloak1 Replication
Browser
en
tia
Note
Base64 means Encoding
Encoding != Encryption
https://jwt.io
Keycloak JSON Web Token Example
Calling Backend Services with Access-Token
1 Authenticated User accesses App
1
App
app.acme.io 2 App uses Access-Token in HTTP
Header to access backend
logged in
Browser
3 Backend looks-up Realm Public
2 5
Key in cache with in Kid from JWT
Authorization: Bearer eyJhbG... Access
Token 4 3a If not found, fetch Public Key with
Kid from Keycloak
• SAML Adapters
• ServletFilter, Tomcat, Jetty, Wildfly ...
• Reverse Proxies
• Keycloak Gatekeeper, dedicated Proxy, written in Go, injects auth info into HTTP headers
• Apache mod_auth_oidc for OpenID Connect
• Apache mod_auth_mellon for SAML
Backend
Spring Boot
OAUTH Bearer-only
Demo Securing Apps
thomasdarimont/keycloak-docker-demo
Let’s see Keycloak in action :)
Keycloak in the Field
How can a Keycloak environment look like?
Demo Environment
Desktop App PlainJS App Frontend Backend SAML App
JavaFX JavaScript Spring Boot Spring Boot Spring Boot
HTTPS Dataflow
sso.tdlabs.local Reverse Proxy
Distributed Cache
Load Balancer / WAF
JGroups / Infinispan
SSL Termination
HTTP(S)
GELF/JSON JMS
Graylog Keycloak
Keycloak Active MQ
Keycloak
JDBC
Thomas Darimont
@thomasdarimont
Links
• Authentication (AuthN)
• Determines who the user is
• Internal & Federated User Storage Kerberos, LDAP, Custom
• Customizable
• Authorization (AuthZ)
• Determines what the user is allowed to do
• Hierarchical Role-based Access Control (HRBAC)
• Authorization Services
• Flexible Access Control Management
• More Variants like ABAC, UBAC, CBAC supported
Supported Single Sign-on Protocols
2 Extract AccessToken
KC_ACCESS_TOKEN=$(echo $KC_RESPONSE | jq -r .access_token)
# eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJGY3RMVHJqeWRxYkpISGZ0d29U ...