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



