com.fatwire.system
Class SessionFactory

java.lang.Object
  extended by com.fatwire.system.SessionFactory

public final class SessionFactory
extends java.lang.Object

This is a factory to create new Session instances or obtain ones already created.

New Session instances are always created for a user, by way of invoking SessionFactory.newSession(java.lang.String, java.lang.String). Session instances are meant to last the lifetime of the thread of execution. It is not advisable to cache an instance of Session and use it across threads.

When Asset API is used in a Content Server managed JSP template, it is advised to obtain an instance of Session that is already created by Content Server by calling SessionFactory.getSession() instead of creating a new Session. The Session obtained by this mechanism is created with the privileges of the user executing the request. Obtaining Session in this way inside a JSP template is essential to getting the page log cache dependencies correctly. While it is possible to obtain a new Session and use it within a JSP page, it is not advised.

Please note that SessionFactory.getSession() is only meaningful when used in a JSP page managed by Content Server. A stand alone JSP page, just as a stand alone Java program, will need to invoke SessionFactory.newSession(java.lang.String, java.lang.String) to start using asset API.


Method Summary
static Session getSession()
          Gets handle to a Session instance using context information registered with the current thread.
static Session getSession(ICS ics)
          This methods gets a session with an existing ics.
static Session newSession(java.lang.String username, java.lang.String password)
          This method creates a new Session backed by given user's privileges.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSession

public static Session getSession()
Gets handle to a Session instance using context information registered with the current thread. This method is intended for use from within Content Server managed JSP pages. If no context is found, this method fails with AssetAccessException.

Returns:
Session created with user information found in registered context within Content Server.
Throws:
java.lang.IllegalStateException - if Content Server is not registered.

newSession

public static Session newSession(java.lang.String username,
                                 java.lang.String password)
This method creates a new Session backed by given user's privileges. When both username and password are null, default user's privilages are used to build a new Session.

Parameters:
username - the username
password - the password
Returns:
Session for a given user, never null
Throws:
java.lang.IllegalStateException - if Content Server session cannot be created
java.lang.SecurityException - if user authentication fails

getSession

public static Session getSession(ICS ics)
This methods gets a session with an existing ics. If the ics passed in is null, a default reader session would be created and returned

Parameters:
ics - the user ics
Returns:
the Session for given user ics