Package com.webmethods.portal.bizPolicy
Interface IContext
- All Superinterfaces:
Cloneable
,ILocaleInfo
,IPrincipalData
,IURI
,Serializable
IContext is the java bean that represents the current user's portal session. It provides a protocol independent way of accessing request and session information. It is guaranteed to always be available for any business logic or presentation logic. If an IContext is accessed from outside of the scope of a current session then it will act as the system user.
IContext can be accessed from anywhere with the following code examples:
IContext context = com.webmethods.portal.bizPolicy.impl.ContextFactory.acquireContext(true);
Or if you have access to the HttpServletRequest, //request = HttpServletRequest
IContext context = com.webmethods.portal.bizPolicy.impl.ContextFactory.acquireContext(request);
IContext holds the following types of information:
- Information about the current user: username, domain, thingID.
- Information about the current request: currentResourceURI, and current Requested Type. (see
PresentationData
for more information. - Attributes: Session or request based attributes that you can use like a
Map
. - Traits: An advanced topic that controls the runtime execution of Portal Verbs.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The default implementation of this interface: com.webmethods.portal.bizPolicy.impl.Contextstatic final String
static final int
Deprecated.static final int
All attributes are stored with a scope.static final int
All attributes are stored with a scope.static final String
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canImpersonate
(IThingID userID) Checks if the current user can impersonate other usersvoid
clearAttributes
(int scope) Clears all the attributes on the IContext that stored stateful user information for a given scope.void
Clears any information messagegetAttribute
(Object key, int scope) Gets an attribute on the IContext that was used to store stateful user information.getAttributes
(int scope) Retrieves all the attributes on the IContext that store stateful user information for the given scope.Retrieves the result of the last command.Returns instance of ContextProvider which created this context instanceRetrieves the current resource.(Probably) Only valid in the webApplication context The type might be for instance: folder, content, wm_xt_rssfeed, etc...Get the internal storage for theIPrincipalData
.Retrieves a message if availableDeprecated.for use only with the PostRenderCacheGet theITraits
object for the current context.boolean
Whether the current context has a messageboolean
This is a clue to the presentation system that this context's request has already rendered the start of a page In case of error, don't rerender all the header infovoid
impersonate
(IThingID userID, boolean isAdmin) Have this context impersonate a user.void
initialize
(IPrincipalData info) Initialize this context using the given principal data object.boolean
Returns true if this is a system context.boolean
isValid()
Describes whether this is context is in a valid state.void
removeAttribute
(Object key, int scope) Removes an attribute on the IContext that stored stateful user information.void
setAttribute
(Object key, Object value, int scope) Sets an attribute on the IContext in order to store stateful user information.void
setAttributes
(Map<? extends Object, ? extends Object> properties, int scope) Sets attributes on the IContext in order to store stateful user information.void
setCommandResult
(Object obj) Sets the command result on the context with SCOPE_REQUEST scope.void
setCurrentResource
(IURI uri) Set the current resource.void
setCurrentResourceType
(String type) void
setInformationalMessage
(int severity, String message) This sets a message that can later be retrieved (stored on the session)void
void
setSystemContext
(boolean isSystemContext) Set whether this is a system context.void
Set theITraits
object for the current context.void
Deprecated.for use only with the PostRenderCachevoid
Deprecated.for use only with the PostRenderCacheMethods inherited from interface com.webmethods.portal.bizPolicy.ILocaleInfo
evaluateLocale, getiContext, getLocale, setLocale, setLocale
Methods inherited from interface com.webmethods.portal.bizPolicy.IPrincipalData
getDN, getDomain, getDomainUserName, getPassword, getUri, getUserDirectoryURI, getUserID, getUserName, isAdminSession, isAnonymous, isAuthenticated, isLoginSession, isPrivilegedInfo, setAuthentication, setDN, setDomain, setInfo, setIsAdminSession, setIsAnonymous, setIsLoginSession, setIsPrivilegedInfo, setUri, setUserID, setUserName
Methods inherited from interface com.webmethods.portal.system.IURI
clone, getSegment, getSegments, getSegments, getServiceName, getSize, initialize, toString
-
Field Details
-
SERVICE_NAME
- See Also:
-
ID
-
DEFAULT_CLASS
The default implementation of this interface: com.webmethods.portal.bizPolicy.impl.Context- See Also:
-
SCOPE_REQUEST
static final int SCOPE_REQUESTAll attributes are stored with a scope. This scope represents attributes that last for a single request. To associate an attribute with the current request, you can do the following:
Then to retrieve the attribute later during the same request use the follwoing:context.setAttribute("myAttrKey", myObjectVal, IContext.SCOPE_REQEUST);
Object myObjectVal = context.getAttribute("myAttrKey", IContext.SCOPE_REQEUST);
-
SCOPE_SESSION
static final int SCOPE_SESSIONAll attributes are stored with a scope. This scope represents attributes that last for a user's session. To associate an attribute with the current user's session, you can do the following:
Then to retrieve the attribute later during the same request use the follwoing:context.setAttribute("myAttrKey", myObjectVal, IContext.SCOPE_SESSION);
Object myObjectVal = context.getAttribute("myAttrKey", IContext.SCOPE_SESSION);
-
SCOPE_APPLICATION
Deprecated.All attributes are stored with a scope. This scope represents attributes that last for the length of the application.- See Also:
-
-
Method Details
-
isValid
boolean isValid()Describes whether this is context is in a valid state. This is only used internally, and should not be necessary to ever check.- Returns:
- true if valid, false otherwise
-
getContextProvider
IContextProvider getContextProvider()Returns instance of ContextProvider which created this context instance- Returns:
-
initialize
Initialize this context using the given principal data object. This is only used internally, and should not be necessary to ever invoke.- Parameters:
info
-IPrincipalData
object
-
getTraits
ITraits getTraits()Get theITraits
object for the current context. This allows you to inspect the current registered traits that control the runtime execution of user's interaction with Portal Verbs.- Returns:
- the
ITraits
object
-
setTraits
Set theITraits
object for the current context. This allows you to set the registered traits that control the runtime execution of user's interaction with Portal Verbs.- Parameters:
traits
- theITraits
object.- See Also:
-
setAttribute
Sets an attribute on the IContext in order to store stateful user information.- Parameters:
key
- the identifier of the datavalue
- the datascope
- the scope of the data- See Also:
-
setAttributes
Sets attributes on the IContext in order to store stateful user information.- Parameters:
properties
- A Map of attributes to storescope
- the scope of the data- See Also:
-
getAttribute
Gets an attribute on the IContext that was used to store stateful user information.- Parameters:
key
- the identifier of the datascope
- the scope of the data- Returns:
- the data if found, NULL otherwise
- See Also:
-
removeAttribute
Removes an attribute on the IContext that stored stateful user information.- Parameters:
key
- the identifier of the datascope
- the scope of the data- See Also:
-
clearAttributes
void clearAttributes(int scope) Clears all the attributes on the IContext that stored stateful user information for a given scope.- Parameters:
scope
- the scope of the data- See Also:
-
getAttributes
Retrieves all the attributes on the IContext that store stateful user information for the given scope.- Parameters:
scope
- the scope of the data- Returns:
- Map of attributes
- See Also:
-
getCommandResult
Object getCommandResult()Retrieves the result of the last command. If this request invoked a Portal Verb, then the result (if any) will be placed on the context in the Request Scope.- Returns:
- the command result value.
- See Also:
-
setCommandResult
Sets the command result on the context with SCOPE_REQUEST scope.- Parameters:
obj
- the command result value to set.- See Also:
-
getCurrentResource
IURI getCurrentResource()Retrieves the current resource. (Probably) Only valid in the webApplication context.- Returns:
- the
IURI
of the current resource
-
setCurrentResource
Set the current resource.- Parameters:
uri
- theIURI
of the current resource- See Also:
-
getCurrentResourceType
String getCurrentResourceType()(Probably) Only valid in the webApplication context The type might be for instance: folder, content, wm_xt_rssfeed, etc...- Returns:
- the type of the current reosurce
-
setCurrentResourceType
- See Also:
-
startTracking
Deprecated.for use only with the PostRenderCacheStart tracking session parameters. -
stopTracking
Deprecated.for use only with the PostRenderCacheStop tracking session parameters. -
getTrackedState
Deprecated.for use only with the PostRenderCacheReturn session tracking state.- Returns:
- the
IContextState
of the current context.
-
isSystemContext
boolean isSystemContext()Returns true if this is a system context. This allows the Session Monitor portlet distinguish between system sessions (non-user) and normal user sessions.- Returns:
- True if this is a system context, False otherwise.
- See Also:
-
setSystemContext
void setSystemContext(boolean isSystemContext) Set whether this is a system context.- Parameters:
isSystemContext
- True if this is a system context, False otherwise.- See Also:
-
canImpersonate
Checks if the current user can impersonate other users- Parameters:
userID
- the user to impersonate- Returns:
- true or false
-
impersonate
Have this context impersonate a user.- Parameters:
userID
- TheIThingID
of the user to impersonate.isAdmin
- True if this is an administrator.- Throws:
PortalException
- if userID is invalid
-
getInternalPrincipalData
IPrincipalData getInternalPrincipalData()Get the internal storage for theIPrincipalData
.- Returns:
- the
IPrincipalData
object for the current context.
-
hasRenderedPageStart
boolean hasRenderedPageStart()This is a clue to the presentation system that this context's request has already rendered the start of a page In case of error, don't rerender all the header info -
setRenderedPageStart
void setRenderedPageStart()- See Also:
-
setInformationalMessage
This sets a message that can later be retrieved (stored on the session)- Parameters:
severity
-message
- already localized message- See Also:
-
getMessage
IInformationalMessage getMessage()Retrieves a message if available- See Also:
-
clearMessage
void clearMessage()Clears any information message- See Also:
-
hasMessage
boolean hasMessage()Whether the current context has a message- See Also:
-