Class EphemeralStore
java.lang.Object
org.apache.juneau.rest.client.mcp.auth.EphemeralStore
Single-use, TTL-bounded store for the per-authorization
state → (codeVerifier, expectedIssuer)
association created when an interactive authorization-code + PKCE flow is started and consumed when the loopback
redirect arrives.
Relocation of the EphemeralStore pattern from juneau-rest-server-auth-oidc-rp for headless
(CLI/desktop) use. The browser-session redirectTarget/nonce shape is dropped; this headless variant
stores the PKCE code_verifier and the discovered expectedIssuer used for the SEP-2468 iss
check on the callback.
Security properties:
- Single-use —
consume(String)atomically removes the entry, so a replayed callback with the samestatefails. - TTL-bounded — entries older than the configured TTL are treated as a miss and swept.
- Size-bounded — an LRU cap (default 1000) prevents unbounded growth from abandoned attempts.
Thread-safe.
- Since:
- 10.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA pending-authorization association awaiting the IdP loopback callback. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximum number of in-flight authorization attempts retained.static final DurationDefault time-to-live for a pending authorization (the user has at most a few minutes at the IdP). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAtomically removes and returns the pending-authorization association forstate, if present and not expired.static EphemeralStorecreate()Creates a store with the default TTL, size cap, and system UTC clock.intsize()Returns the current entry count.voidStores a pending-authorization association keyed bystate.
-
Field Details
-
DEFAULT_MAX_ENTRIES
Default maximum number of in-flight authorization attempts retained.- See Also:
-
DEFAULT_TTL
Default time-to-live for a pending authorization (the user has at most a few minutes at the IdP).
-
-
Constructor Details
-
EphemeralStore
Constructor.- Parameters:
ttl- The single-use TTL. Must be positive and not exceed 30 minutes.maxEntries- The LRU size cap. Must be positive.clock- The clock for TTL comparisons. Must not benull .
-
-
Method Details
-
create
Creates a store with the default TTL, size cap, and system UTC clock.- Returns:
- A new store.
-
store
Stores a pending-authorization association keyed bystate.- Parameters:
state- The opaquestatevalue. Must not benull or blank.codeVerifier- The PKCEcode_verifier. Must not benull or blank.expectedIssuer- The discovered issuer for the SEP-2468isscheck. May benull .
-
consume
Atomically removes and returns the pending-authorization association forstate, if present and not expired.- Parameters:
state- Thestatevalue from the callback. Must not benull .- Returns:
- The association, or
Optional.empty()if absent or expired.
-
size
Returns the current entry count. Primarily for tests and metrics.- Returns:
- The entry count.
-