Package org.forgerock.services.context
Class AbstractContext
java.lang.Object
org.forgerock.services.context.AbstractContext
- All Implemented Interfaces:
- Context
- Direct Known Subclasses:
- AdviceContext,- ApiVersionRouterContext,- AttributesContext,- AuditingContext,- AuthRedirectContext,- CapturedUserPasswordContext,- CdSsoContext,- CdSsoFailureContext,- ClientContext,- FailureContext,- FileAttributesContext,- HttpContext,- IdentityRequestJwtContext,- InternalSsoTokenContext,- JwtBuilderContext,- JwtValidationContext,- JwtValidationErrorContext,- OAuth2Context,- OAuth2FailureContext,- OAuth2SessionContext,- OAuth2TokenExchangeContext,- PolicyDecisionContext,- RequestAuditContext,- RootContext,- RoutingContext,- SamlFailureContext,- SecurityContext,- SessionContext,- SessionInfoContext,- SqlAttributesContext,- SsoTokenContext,- StsContext,- TransactionIdContext,- UriRouterContext,- UserProfileContext
A base implementation of the 
Context interface. Derived Contexts MUST support persistence by providing
 - a public constructor having the same declaration as
 AbstractContext(JsonValue, ClassLoader)
- a public method having the same declaration as
 Context.toJsonValue()
Here is an example of the JSON representation of the core attributes of all contexts:
 {
   "id"     : "56f0fb7e-3837-464d-b9ec-9d3b6af665c3",
   "class"  : ...Java class name..,
   "parent" : {
       ...
   }
 }
 - 
Field SummaryFields
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedAbstractContext(String id, String name, Context parent) Constructs a newAbstractContext.AbstractContext(JsonValue savedContext, ClassLoader classLoader) Creates a new context from the JSON representation of a previously persisted context.protectedAbstractContext(Context parent, String name) Constructs a newAbstractContextwith anullid.
- 
Method SummaryModifier and TypeMethodDescriptionReturns 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.final <T extends Context>
 TReturns the first context in the chain whose type is a sub-type of the providedContextclass.final booleancontainsContext(Class<? extends Context> clazz) Returnstrueif there is a context in the chain whose type is a sub-type of the providedContextclass.final booleancontainsContext(String contextName) Returnstrueif there is a context in the chain whose name matches the provided context name.final ContextgetContext(String contextName) Returns the first context in the chain whose context name matches the provided name.final StringGet this Context's name.final StringgetId()Returns the unique ID identifying this context, usually a UUID.final ContextReturns the parent of this context.Returns the unique ID of the root context, usually a UUID.final booleanReturnstrueif this context is a root context.Return this Context as a JsonValue (for persistence).toString()
- 
Field Details- 
dataThe Context data.
 
- 
- 
Constructor Details- 
AbstractContextConstructs a newAbstractContextwith anullid.- Parameters:
- parent- The parent context.
- name- The name of the context.
 
- 
AbstractContextConstructs a newAbstractContext.- Parameters:
- id- The id of the context.
- parent- The parent context.
- name- The name of the context.
 
- 
AbstractContextCreates a new context from the JSON representation of a previously persisted context.Sub-classes MUST provide a constructor having the same declaration as this constructor in order to support persistence. Implementations MUST take care to invoke the super class implementation before parsing their own context attributes. Below is an example implementation for a security context which stores the user name and password of the authenticated user: protected SecurityContext(JsonValue savedContext, ClassLoader classLoader) { // Invoke the super-class implementation first. super(savedContext, classLoader); // Now parse the attributes for this context. this.username = savedContext.get("username").required().asString(); this.password = savedContext.get("password").required().asString(); }In order to create a context's persisted JSON representation, implementations must override.- Parameters:
- savedContext- The JSON representation from which this context's attributes should be parsed.
- classLoader- The ClassLoader which can properly resolve the persisted class-name.
 
 
- 
- 
Method Details- 
getContextNameDescription copied from interface:ContextGet this Context's name.- Specified by:
- getContextNamein interface- Context
- Returns:
- this object's name
 
- 
asContextDescription copied from interface:ContextReturns 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.
- 
asDescription copied from interface:ContextReturns 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.- Specified by:
- asin interface- Context
- 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.
 
- 
getContextDescription copied from interface:ContextReturns the first context in the chain whose context name matches the provided name.- Specified by:
- getContextin interface- Context
- Parameters:
- contextName- The name of the context to be returned.
- Returns:
- The first context in the chain whose name matches the provided context name.
 
- 
getDescription copied from interface:Context
- 
containsContextDescription copied from interface:ContextReturnstrueif 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.- Specified by:
- containsContextin interface- Context
- 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.
 
- 
containsContextDescription copied from interface:ContextReturnstrueif there is a context in the chain whose name matches the provided context name.- Specified by:
- containsContextin interface- Context
- Parameters:
- contextName- The name of the context to locate.
- Returns:
- trueif there is a context in the chain whose context name matches- contextName.
 
- 
getIdDescription copied from interface:ContextReturns 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.
- 
getRootIdDescription copied from interface:ContextReturns the unique ID of the root context, usually a UUID.
- 
getParentDescription copied from interface:ContextReturns the parent of this context.
- 
isRootContextpublic final boolean isRootContext()Description copied from interface:ContextReturnstrueif this context is a root context.- Specified by:
- isRootContextin interface- Context
- Returns:
- trueif this context is a root context.
 
- 
toJsonValueDescription copied from interface:ContextReturn this Context as a JsonValue (for persistence).- Specified by:
- toJsonValuein interface- Context
- Returns:
- the Context data as a JsonValue.
 
- 
toString
 
-