Package org.forgerock.services.context
Interface Context
- 
- All Known Implementing Classes:
- AbstractContext,- AdviceContext,- ApiVersionRouterContext,- AttributesContext,- AuditingContext,- AuthRedirectContext,- CapturedUserPasswordContext,- CdSsoContext,- CdSsoFailureContext,- ClientContext,- HttpContext,- InternalSsoTokenContext,- JwtBuilderContext,- JwtValidationContext,- JwtValidationErrorContext,- OAuth2Context,- OAuth2FailureContext,- OAuth2SessionContext,- OAuth2TokenExchangeContext,- PolicyDecisionContext,- RequestAuditContext,- RootContext,- RoutingContext,- SamlFailureContext,- SecurityContext,- SessionContext,- SessionInfoContext,- SsoTokenContext,- StsContext,- TransactionIdContext,- UriRouterContext,- UserProfileContext,- WebSocketHandshakeContext
 
 public interface ContextType-safe contextual information associated with the processing of a request in an application. Contexts are linked together in a stack with aRootContextat the bottom of the stack. Each context maintains a reference to its parent context which can be accessed using thegetParent()} method. Context implementations may provide information about the client, the end-user, auditing information, routing decisions, etc. While contexts are arranged in a stack, application code will usually access contexts using theasContext(Class)method:Context context = ...; // Opaque reference to the context stack String remoteHost = context.asContext(ClientContext.class).getRemoteHost(); context.asContext(AttributesContext.class).getAttributes().put("key", "value");Alternatively, scripted applications will usually access contexts by name:var remoteHost = context.client.remoteHost; context.attributes.key = "value";Context implementations should inherit fromAbstractContextand ensure that they can be serialized to and from JSON.
- 
- 
Method SummaryAll Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <T extends Context>
 Optional<T>as(Class<T> clazz)Returns an @{link Optional} which contains the first context in the chain whose type is a sub-type of the providedContextclass if one exists, or an empty optional if none is present.<T extends Context>
 TasContext(Class<T> clazz)Returns the first context in the chain whose type is a sub-type of the providedContextclass.booleancontainsContext(Class<? extends Context> clazz)Returnstrueif there is a context in the chain whose type is a sub-type of the providedContextclass.booleancontainsContext(String contextName)Returnstrueif there is a context in the chain whose name matches the provided context name.default Optional<Context>get(String contextName)ContextgetContext(String contextName)Returns the first context in the chain whose context name matches the provided name.StringgetContextName()Get this Context's name.StringgetId()Returns the unique ID identifying this context, usually a UUID.ContextgetParent()Returns the parent of this context.StringgetRootId()Returns the unique ID of the root context, usually a UUID.booleanisRootContext()Returnstrueif this context is a root context.JsonValuetoJsonValue()Return this Context as a JsonValue (for persistence).
 
- 
- 
- 
Method Detail- 
getContextNameString getContextName() Get this Context's name.- Returns:
- this object's name
 
 - 
asContext<T extends Context> T asContext(Class<T> clazz) Returns the first context in the chain whose type is a sub-type of the providedContextclass. The method first checks this context to see if it has the required type, before proceeding to the parent context, and then continuing up the chain of parents until the root context is reached.- Type Parameters:
- T- The context type.
- Parameters:
- clazz- The class of context to be returned.
- Returns:
- The first context in the chain whose type is a sub-type of the
         provided Contextclass.
- Throws:
- IllegalArgumentException- If no matching context was found in this context's parent chain.
 
 - 
asdefault <T extends Context> Optional<T> as(Class<T> clazz) Returns an @{link Optional} which contains the first context in the chain whose type is a sub-type of the providedContextclass if one exists, or an empty optional if none is present. The method first checks this context to see if it has the required type, before proceeding to the parent context, and then continuing up the chain of parents until the root context is reached.- Type Parameters:
- T- The context type.
- Parameters:
- clazz- The class of context to be returned.
- Returns:
- An Optionalcontaining the first context in the chain whose type is a sub-type of the providedContextclass, or an empty optional if no such Context exists in the chain.
 
 - 
getContextContext getContext(String contextName) Returns the first context in the chain whose context name matches the provided name.- Parameters:
- contextName- The name of the context to be returned.
- Returns:
- The first context in the chain whose name matches the provided context name.
- Throws:
- IllegalArgumentException- If no matching context was found in this context's parent chain.
 
 - 
getdefault Optional<Context> get(String contextName) Returns anOptionalcontaining the first context in the chain whose context name matches the provided name, or an emptyOptionalif none is present.- Parameters:
- contextName- The name of the context to be returned.
- Returns:
- An Optionalcontaining the first context in the chain whose name matches the provided context name, an empty optional if none is present.
 
 - 
containsContextboolean containsContext(Class<? extends Context> clazz) Returnstrueif there is a context in the chain whose type is a sub-type of the providedContextclass. The method first checks this context to see if it has the required type, before proceeding to the parent context, and then continuing up the chain of parents until the root context is reached.- Parameters:
- clazz- The class of context to be checked.
- Returns:
- trueif there is a context in the chain whose type is a sub-type of the provided- Contextclass.
 
 - 
containsContextboolean containsContext(String contextName) Returnstrueif there is a context in the chain whose name matches the provided context name.- Parameters:
- contextName- The name of the context to locate.
- Returns:
- trueif there is a context in the chain whose context name matches- contextName.
 
 - 
getIdString getId() Returns the unique ID identifying this context, usually a UUID. If no ID has been defined then the ID of the parent context will be returned.- Returns:
- The unique ID identifying this context. If no ID has been defined then the ID of the parent context will be returned.
 
 - 
getRootIdString getRootId() Returns the unique ID of the root context, usually a UUID.- Returns:
- The unique ID of the root context.
 
 - 
getParentContext getParent() Returns the parent of this context.- Returns:
- The parent of this context, or nullif this context is a root context.
 
 - 
isRootContextboolean isRootContext() Returnstrueif this context is a root context.- Returns:
- trueif this context is a root context.
 
 - 
toJsonValueJsonValue toJsonValue() Return this Context as a JsonValue (for persistence).- Returns:
- the Context data as a JsonValue.
 
 
- 
 
-