Package wt.session

Class SessionContext

All Implemented Interfaces:
Serializable, Cloneable, Map

public class SessionContext extends Hashtable
A specialized Hashtable for maintaining static context partitioned by user session.

Supported API: true
Extendable: false
See Also:
  • Constructor Details

    • SessionContext

      public SessionContext()
      Construct a new session context. The new context is not added to the session cache until register is called. Until registered, there is no unique session id associated with this object.

      Supported API: true
  • Method Details

    • getSessionId

      public String 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

      public static SessionContext 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

      public static SessionContext getContext(boolean authenticate)
      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

      public static SessionContext getContext(String session_id)
      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

      public Object put(Object key, Object value)
      Put a new value in this method context. Overrides hashtable.put to update master session cache maintained in the server manager and add property change support.

      Supported API: true
      Specified by:
      put in interface Map
      Overrides:
      put in class Hashtable
    • remove

      public Object remove(Object key)
      Remove a value from this session context. Overrides Hashtable.remove to update master session cache maintained in the server manager and add property change support.

      Supported API: true
      Specified by:
      remove in interface Map
      Overrides:
      remove in class Hashtable
    • setContext

      public static SessionContext setContext(SessionContext session_context)
      Explicitly set the SessionContext object associated with the current thread. This method will typically be used in conjunction with a try/finally block 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 - a SessionContext object or null
      Returns:
      previous value
      See Also:
    • newContext

      public static SessionContext newContext()
      Create a new SessionContext object associated with the current thread. This method will typically be used in conjunction with a try/finally block. 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

      public static WTPrincipal setEffectivePrincipal(WTPrincipal principal)
      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/finally block 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 - a WTPrincipal object or null
      Returns:
      previous value
    • getEffectivePrincipal

      public static WTPrincipal 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:
      Principal object or null if not set.
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener listener)
      Add a PropertyChangeListener to 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 - the PropertyChangeListener to be added
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener listener)
      Remove a PropertyChangeListener from the listener list.

      Supported API: true
      Parameters:
      listener - the PropertyChangeListener to be removed
    • getContext

      public static SessionContext getContext(String prefix, String sessionId)
      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 key
      sessionId - session id of the JSP/Servlet engine calling the method server
      Returns:
      the session context
      See Also: