The Simplest Way to Make Jetty and Keycloak Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Jetty and Keycloak work together to secure Java web apps with central login rules. Keycloak checks user identity and sends signed tokens to the Jetty server. This setup lets teams run fast web servers while keeping user rules in one place. Developers do not need to write custom login code for every new service. Instead, the server checks tokens and grants the right level of access. How jetty and keycloak handle login and roles The login flow between jetty and keycloak relies on open standards

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Jetty and Keycloak work together to secure Java web apps with central login rules. Keycloak checks user identity and sends signed tokens to the Jetty server. This setup lets teams run fast web servers while keeping user rules in one place. Developers do not need to write custom login code for every new service. Instead, the server checks tokens and grants the right level of access.

How jetty and keycloak handle login and roles

The login flow between jetty and keycloak relies on open standards like OpenID Connect. A user tries to open a protected page on the Jetty web server. Jetty sees that the user has no active session and pauses the request. It sends the user browser straight to the Keycloak login screen. The user types in their name and password and completes a second check.

Keycloak checks these details against its user store or a company directory. Once the check passes, Keycloak builds a signed JSON token for that user. This token holds the user identity, group memberships, and specific app roles. The browser carries this signed token back to the Jetty server. Jetty checks the digital signature using public keys from the identity server.

If the signature matches, Jetty reads the roles inside the token payload. The web server matches those token roles to its own internal security rules. When the user has the right role, Jetty serves the requested web page. If the role is missing, the server blocks the request right away. This flow keeps passwords off the web server and centralizes role checks.

Common token errors and how to scope access

Teams often run into trouble when they share one client setup across apps. A broad token valid for one service might manage another service by mistake. Long token lifetimes also create risk when an employee leaves the team. If a token stays valid for hours, revoking access takes too much time. Unlogged requests inside the web server make security reviews very hard to finish.

You can fix these gaps by scoping roles and network paths with care. Create a separate client entry in Keycloak for every single Jetty app. Set token lifetimes to a few minutes so old sessions expire fast. Map narrow roles to each route instead of giving broad admin rights. Restrict network paths so Jetty only talks to Keycloak over encrypted links.

Keycloak + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Keeping audit logs and data safe in production

Securing the login step is only half of the production security job. Once a user logs in, the app still runs queries and returns data. You need clear logs that link every server action to a real person. Standard web logs often show an IP address but miss the user identity. Teams should write the user ID from the token into every log line.

Data protection also matters when apps return sensitive records to the browser. Masking rules can rewrite matched fields in results, like emails or card numbers. You can also mask phone numbers and national IDs before they leave the server. Combining strict token checks with data masking keeps production systems safe during daily work.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Does Jetty need a special plugin to work with Keycloak?

Modern setups use standard OpenID Connect libraries rather than older vendor adapters. Any standard OIDC library for Java can check Keycloak tokens inside Jetty.

How does Jetty verify a token without calling Keycloak every time?

Jetty fetches public signing keys from Keycloak and caches them in memory. It uses these public keys to check token signatures locally at high speed.

What happens when a user role changes during an active session?

The new role takes effect when Jetty requests a fresh access token. Short token lifetimes make sure role updates apply within a few minutes.

The query runs. The emails stay hidden.