Package wt.session
Class SessionContext
java.lang.Object
java.util.Dictionary<K,V>
java.util.Hashtable
wt.session.SessionContext
- All Implemented Interfaces:
Serializable,Cloneable,Map
A specialized Hashtable for maintaining static context partitioned by user session.
Supported API: true
Extendable: false
Supported API: true
Extendable: false
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAutoCloseableimplementation for establishing a SessionContext for a clearly delimited scope, restoring the previous SessionContext upon leaving this scope. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd aPropertyChangeListenerto the listener list.static SessionContextGet current session context.static SessionContextgetContext(boolean authenticate) Get current session context.static SessionContextgetContext(String session_id) Get the session context corresponding to a given session id.static SessionContextgetContext(String prefix, String sessionId) Get current session context using a "prefix" and the JSP/Servlet Session Id as the key.static WTPrincipalGet the effective principal object associated with the current thread.Get the unique session id associated with this context.static SessionContextCreate a newSessionContextobject associated with the current thread.Put a new value in this method context.voidregister()Register a session context in the session cache.Remove a value from this session context.voidRemove aPropertyChangeListenerfrom the listener list.static SessionContextsetContext(SessionContext session_context) Explicitly set theSessionContextobject associated with the current thread.static WTPrincipalsetEffectivePrincipal(WTPrincipal principal) Set the effective principal object associated with the current thread.Methods inherited from class java.util.Hashtable
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, merge, putAll, putIfAbsent, rehash, remove, replace, replace, replaceAll, size, toString, values
-
Constructor Details
-
SessionContext
public SessionContext()Construct a new session context. The new context is not added to the session cache untilregisteris called. Until registered, there is no unique session id associated with this object.
Supported API: true
-
-
Method Details
-
getSessionId
Get the unique session id associated with this context.
Supported API: true- Returns:
- the session id
-
register
public void register()Register a session context in the session cache.
Supported API: true -
getContext
Get current session context. Session context is determined by authentication information in the current Method context. If none exists, an unauthenticated session context will be established.
Supported API: true- Returns:
- the session context
- See Also:
-
getContext
Get current session context. Session context is determined by authentication information in the current Method context. If none exists, a new session context will be establised, optionally performing user authentication in the process.
Supported API: true- Parameters:
authenticate- perform user authentication if creating a new session context.- Returns:
- the session context
- See Also:
-
getContext
Get the session context corresponding to a given session id.
Supported API: true- Parameters:
session_id- the session id- Returns:
- the corresponding session context or null if not found in the session cache
-
put
Put a new value in this method context. Overrideshashtable.putto update master session cache maintained in the server manager and add property change support.
Supported API: true -
remove
Remove a value from this session context. OverridesHashtable.removeto update master session cache maintained in the server manager and add property change support.
Supported API: true -
setContext
Explicitly set theSessionContextobject associated with the current thread. This method will typically be used in conjunction with atry/finallyblock to reset the value later. Setting to null restores the default. For example:... SessionContext new_context = ... SessionContext previous_context = SessionContext.setContext(new_context); try { SessionMgr.setPrincipal(AdministrativeDomainHelper.ADMINISTRATOR_NAME); doAdminStuff(); } catch (...) { ... } finally { SessionContext.setContext(previous_context); }
Supported API: true- Parameters:
session_context- aSessionContextobject or null- Returns:
- previous value
- See Also:
-
newContext
Create a newSessionContextobject associated with the current thread. This method will typically be used in conjunction with atry/finallyblock. For example:... SessionContext previous_context = SessionContext.newContext(); try { SessionMgr.setPrincipal(AdministrativeDomainHelper.ADMINISTRATOR_NAME); doAdminStuff(); } catch (...) { ... } finally { SessionContext.setContext(previous_context); }
Supported API: true- Returns:
- previous value
-
setEffectivePrincipal
Set the effective principal object associated with the current thread. The effective principal is used for access control checks. If not explicitly set, access control will use the session principal. Setting to null restores the default.This method will typically be used in conjunction with a
try/finallyblock to reset the value later. For example:... WTPrincipal principal = ... WTPrincipal previous = SessionContext.setEffectivePrincipal(principal); try { // Do special stuff } catch (...) { ... } finally { SessionContext.setEffectivePrincipal(previous); }
Supported API: true- Parameters:
principal- aWTPrincipalobject or null- Returns:
- previous value
-
getEffectivePrincipal
Get the effective principal object associated with the current thread. If the effective principal has not explicitly been set, null is returned.
Supported API: true- Returns:
Principalobject or null if not set.
-
addPropertyChangeListener
Add aPropertyChangeListenerto the listener list. Property change events will be fired to all registered listeners whenever a value in this hashtable is added, changed, or removed.
Supported API: true- Parameters:
listener- thePropertyChangeListenerto be added
-
removePropertyChangeListener
Remove aPropertyChangeListenerfrom the listener list.
Supported API: true- Parameters:
listener- thePropertyChangeListenerto be removed
-
getContext
Get current session context using a "prefix" and the JSP/Servlet Session Id as the key.
Supported API: true- Parameters:
prefix- used guarentee uniqueness to the keysessionId- session id of the JSP/Servlet engine calling the method server- Returns:
- the session context
- See Also:
-