com.iplanet.portalserver.session
Class Session

java.lang.Object
  |
  +--com.iplanet.portalserver.session.Session

public class Session
extends java.lang.Object

The Session class represents a session. It contains session related information such as session ID, session type (user/application), client ID (user ID or application ID), session idle time, time left on the session, and session state. It also allows applications to add listener for session events.

 The following is the state diagram for a session:

                    |
                    |
                    |
                    V
      ---------- invalid
     |              |  
     |              |creation (authentication OK)
     |              |
     |max login time|   max idle time
     |destroy       V  --------------->
     |            valid              inactive --
     |              |  <--------------           |
     |              |       reactivate           |
     |              |                            |
     |              | logout                     | destroy
     |              | destroy                    | max session time
     |              | max session time           | 
     |              V                            |
      --------->  destroy  <---------------------       

 

See Also:
SessionID, SessionListener

Field Summary
static int APPLICATION_SESSION
           
static int DESTROYED
           
static int INACTIVE
           
static int INVALID
           
static java.lang.String SESSION_SERVICE
           
static int USER_SESSION
           
static int VALID
           
 
Method Summary
 void addSessionListener(SessionListener listener)
          Adds a session listener for session change events.
 void addSessionListenerOnAllSessions(SessionListener listener)
          Adds a session listner for all sessions residing on the same session server as this session object resides.
 void addSessionListenerOnAllSessions(java.lang.String server, SessionListener listener)
          Adds a session listner for all sessions on the specified session server.
 void destroySession(Session session)
          Destroy a session.
 java.lang.String encodeURL(javax.servlet.http.HttpServletResponse res, java.lang.String url)
          Returns the encoded URL , rewriten to include the session id.
 java.lang.String encodeURL(java.lang.String url)
          Returns the encoded URL , rewritten to include the session id.
 Profile getAppProfile(java.lang.String name)
          Gets the application profile.
 java.lang.String getClientDomain()
          Returns the client domain in the session.
 java.lang.String getClientID()
          Returns the client ID in the session.
 int getEventType()
          Returns the type of the event which caused the state change of this session.
 SessionID getID()
          Returns the session ID.
 long getIdleTime()
          Returns the session idle time in seconds.
 long getMaxCachingTime()
          Returns the maximum session caching time in minutes.
 long getMaxIdleTime()
          Returns the maximum session idle time in minutes.
 long getMaxSessionTime()
          Returns the maximum session time in minutes.
 java.lang.String getProperty(java.lang.String name)
          Gets the property stored in this session.
static Session getSession(SessionID sid)
          Gets a session based on a SessionID object.
 int getState(boolean reset)
          Returns the state of the session.
 long getTimeLeft()
          Returns the time left for this session in seconds.
 int getType()
          Returns the session type.
 Profile getUserProfile()
          Gets the user (client) profile in this session.
 java.util.Vector getValidSessions()
          Gets all valid sessions residing on the same session server as this session object resides from the Session Service.
 java.util.Vector getValidSessions(java.lang.String server)
          Gets all valid sessions from the specified session server.
 void logout()
          Logout a session.
 void refresh(boolean reset)
          Gets the latest session from session server and updates the local cache of this session.
 void setDebug(Debug debug, java.lang.String profileName)
          Enables or disables degbugging/logging based on the value of debug attributes inside the application profile, which is accessible from the Session, sess.
 void setProperty(java.lang.String name, java.lang.String value)
          Sets a property for this session.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INVALID

public static final int INVALID

VALID

public static final int VALID

INACTIVE

public static final int INACTIVE

DESTROYED

public static final int DESTROYED

USER_SESSION

public static final int USER_SESSION

APPLICATION_SESSION

public static final int APPLICATION_SESSION

SESSION_SERVICE

public static final java.lang.String SESSION_SERVICE
Method Detail

getID

public SessionID getID()
Returns the session ID.
Parameters:
None. -  
Returns:
The session ID.

getType

public int getType()
Returns the session type.
Parameters:
None. -  
Returns:
The session type.

getClientID

public java.lang.String getClientID()
Returns the client ID in the session.
Parameters:
None. -  
Returns:
The client ID in the session.

getClientDomain

public java.lang.String getClientDomain()
Returns the client domain in the session.
Parameters:
None. -  
Returns:
The client domain in the session.

getMaxSessionTime

public long getMaxSessionTime()
Returns the maximum session time in minutes.
Parameters:
None. -  
Returns:
The maximum session time.

getMaxIdleTime

public long getMaxIdleTime()
Returns the maximum session idle time in minutes.
Parameters:
None. -  
Returns:
The maximum session idle time.

getMaxCachingTime

public long getMaxCachingTime()
Returns the maximum session caching time in minutes.
Parameters:
None. -  
Returns:
The maximum session caching time.

getIdleTime

public long getIdleTime()
                 throws SessionException
Returns the session idle time in seconds.
Parameters:
None. -  
Returns:
The session idle time.
Throws:
A - SessionException is thrown if the session reached its maximum session time, or the session was destroyed, or there was an error during communication with session service.

getTimeLeft

public long getTimeLeft()
                 throws SessionException
Returns the time left for this session in seconds.
Parameters:
None. -  
Returns:
The time left for this session.
Throws:
A - SessionException is thrown if the session reached its maximum session time, or the session was destroyed, or there was an error during communication with session service.

getState

public int getState(boolean reset)
             throws SessionException
Returns the state of the session.
Parameters:
reset - This parameter indicates that whether the Session Service needs to reset the latest access time on this session.
Returns:
The state of the session. The session state is one of the following: INVALID, VALID, INACTIVE, and DESTROYED.
Throws:
A - SessionException is thrown if the session reached its maximum session time, or the session was destroyed, or there was an error during communication with session service.

getEventType

public int getEventType()
Returns the type of the event which caused the state change of this session.
Parameters:
None. -  
Returns:
The type of the event. The event types are defined in class SessionEvent as static integers : SESSION_CREATION, IDLE_TIMEOUT, MAX_TIMEOUT, LOGOUT, ACTIVATION, REACTIVATION, and DESTROY.

getProperty

public java.lang.String getProperty(java.lang.String name)
                             throws SessionException
Gets the property stored in this session.
Parameters:
name - The property name.
Returns:
The property value in String format.
Throws:
A - SessionException is thrown if the session reached its maximum session time, or the session was destroyed, or there was an error during communication with session service.

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
                 throws SessionException
Sets a property for this session.
Parameters:
name - The property name.
value - The property value.
Throws:
A - SessionException is thrown if the session reached its maximum session time, or the session was destroyed, or there was an error during communication with session service.

destroySession

public void destroySession(Session session)
                    throws SessionException
Destroy a session.
Parameters:
session - The session to be destroyed.
Returns:
None.
Throws:
A - SessionException is thrown if there was an error during communication with session service. If the session was destroyed already, no exception will be thrown.

logout

public void logout()
            throws SessionException
Logout a session.
Parameters:
None. -  
Returns:
None.
Throws:
A - SessionException is thrown if there was an error during communication with session service. If the session logged out already, no exception will be thrown.

getUserProfile

public Profile getUserProfile()
                       throws ProfileException
Gets the user (client) profile in this session.
Parameters:
None. -  
Returns:
The profile of the user (client) in this session.
Throws:
A - ProfileException is thrown if the session state is not VALID.

getAppProfile

public Profile getAppProfile(java.lang.String name)
                      throws ProfileException
Gets the application profile.
Parameters:
name - The Name of the application.
Returns:
The profile of the application.
Throws:
A - ProfileException is thrown if the session state is not VALID.

addSessionListener

public void addSessionListener(SessionListener listener)
                        throws SessionException
Adds a session listener for session change events.
Parameters:
listener - A reference to a SessionListener object.
Returns:
None.
Throws:
A - SessionException is thrown if the session state is not VALID.

getSession

public static Session getSession(SessionID sid)
                          throws SessionException
Gets a session based on a SessionID object.
Parameters:
sid - The SessionID object.
Returns:
A Session object.
Throws:
A - SessionException is thrown if the SessionID object doesn't contain a valid session string, or the session string was valid before but has been destroyed, or there was an error during communication with session service.

getValidSessions

public java.util.Vector getValidSessions()
                                  throws SessionException
Gets all valid sessions residing on the same session server as this session object resides from the Session Service. This session is subject to access control in order to get all sessions.
Parameters:
None. -  
Returns:
A Vector of Session objects.
Throws:
A - SessionException is thrown if there was an error during communication with session service.

getValidSessions

public java.util.Vector getValidSessions(java.lang.String server)
                                  throws SessionException
Gets all valid sessions from the specified session server. This session is subject to access control in order to get all sessions.
Parameters:
server - The session server name. If the server name contains protocol and port, the protocol and port will be used. Otherwise, the server protocol and port is default to the same protocol and port of the calling session.
Returns:
A Vector of Session objects.
Throws:
A - SessionException is thrown if there was an error during communication with session service.

addSessionListenerOnAllSessions

public void addSessionListenerOnAllSessions(SessionListener listener)
                                     throws SessionException
Adds a session listner for all sessions residing on the same session server as this session object resides. This session is subject to access control in order to receive session events on all sessions.
Parameters:
listener - A reference to the SessionListener object.
Returns:
None.
Throws:
A - SessionException is thrown if there was an error during communication with session service.

addSessionListenerOnAllSessions

public void addSessionListenerOnAllSessions(java.lang.String server,
                                            SessionListener listener)
                                     throws SessionException
Adds a session listner for all sessions on the specified session server. This session is subject to access control in order to receive session events on all sessions. If the server name contains protocol and port, the protocol and port will be used. Otherwise, the server protocol and port is default to the same protocol and port of the calling session.
Parameters:
server - The session server name.
listener - A reference to the SessionListener object.
Returns:
None.
Throws:
A - SessionException is thrown if there was an error during communication with session service.

refresh

public void refresh(boolean reset)
             throws SessionException
Gets the latest session from session server and updates the local cache of this session.
Parameters:
reset - The flag to indicate whether to reset the latest session access time in the session server.
Returns:
None.
Throws:
A - SessionException is thrown if the session reached its maximum session time, or the session was destroyed, or there was an error during communication with session service.

setDebug

public void setDebug(Debug debug,
                     java.lang.String profileName)
              throws ProfileException

Enables or disables degbugging/logging based on the value of debug attributes inside the application profile, which is accessible from the Session, sess.


encodeURL

public java.lang.String encodeURL(javax.servlet.http.HttpServletResponse res,
                                  java.lang.String url)
Returns the encoded URL , rewriten to include the session id.
Parameters:
HttpServletResponse -  
url - , the URL to be encoded
Returns:
the encoded URL if cookies are not supported and url if cookies are supported

encodeURL

public java.lang.String encodeURL(java.lang.String url)
Returns the encoded URL , rewritten to include the session id.
Parameters:
url - , the URL to be encoded
Returns:
the encoded URL if cookies are not supported or the url if cookies are supported.