liveBook · Manning

Security context

As explained in Quarkus in Action

A security context is information describing the authenticated principal and associated security state for a request or interaction.

A security context exposes the authenticated principal and related security state for the current request. A REST endpoint can inspect it without passing user identity through every method explicitly. section 6.2.1 section 6.6

Use the context to connect request authentication with application behavior:

  • Inject jakarta.ws.rs.core.SecurityContext into a REST resource. section 6.2.1
  • Call getUserPrincipal() to obtain the current principal, then read its name. section 6.2.1 section 6.6
  • Handle an empty context explicitly when unauthenticated requests remain allowed. section 6.2.1
  • Use the principal to associate records with users or filter results to the current user. section 6.2.1

Associate a reservation with its principal

String userId = context.getUserPrincipal() != null ? context.getUserPrincipal().getName() : "anonymous"; reservation.userId = userId; section 6.2.1

How Quarkus in Action covers it

How deep it goes
Explains injection, principal lookup, anonymous handling, and filtering, but does not detail authentication-provider internals.
Examples
Demonstrates reservation creation, anonymous fallback, user ownership, and current-user reservation filtering.
What it assumes
Builds on authenticated requests and OIDC-based application security while retaining an explicit unauthenticated case.
What you can do after
Apply it via Jakarta REST injection to identify request users and enforce user-specific application behavior.
How it connects
Connects REST endpoints, principals, OIDC, Keycloak, access tokens, and REST-client token propagation.

Also explained in

Compare how 4 books explain security context →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.