com.flexive.shared
Class FxContext

java.lang.Object
  extended by com.flexive.shared.FxContext
All Implemented Interfaces:
java.io.Serializable

public class FxContext
extends java.lang.Object
implements java.io.Serializable

The [fleXive] context - user session specific data like UserTickets, etc.

Author:
Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at), Gregor Schober (gregor.schober@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at), Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
See Also:
Serialized Form

Field Summary
static java.lang.String ADMIN_AUTHENTICATED
          Session key set if the user successfully logged into the admin area
static int DIV_GLOBAL_CONFIGURATION
          Global division id
static int DIV_UNDEFINED
          Undefined division id
static java.lang.String SESSION_DIVISIONID
          Session key for the session division ID.
 
Method Summary
static FxContext _getEJBContext(FxContext template)
          Get a FxContext instance to use at the EJB layer.
 void _reloadUserTicket()
          Reload the UserTicket, needed i.e.
static void cleanup()
          Performs a cleanup of the stored informations.
static FxContext get()
          Gets the session information for the running thread
 java.lang.String getAbsolutePath(java.lang.String path)
          Returns the absolute path for the given resource (i.e.
 java.lang.String getApplicationId()
          Returns the id of the appication the request was made in.
 java.lang.String getContextPath()
          Return the context path of this request.
 int getDivisionId()
          Returns the id of the division.
 FxLanguage getLanguage()
          Get the current users preferred language
protected static UserTicket getLastUserTicket(javax.servlet.http.HttpSession session)
           
 java.util.Locale getLocale()
          Get the current users preferred locale (based on his preferred language)
 long getNodeId()
          Get the current users active tree node id (CMS extension)
 java.lang.String getRelativeRequestURI()
          Returns the decoded relative request URI.
 java.lang.String getRelativeRequestURI(boolean decode)
          Returns the relative request URI.
 java.lang.String getRemoteHost()
          Returns the calling remote host.
 java.lang.String getRequestURI()
          Returns the request URI.
 java.lang.String getRequestUriNoContext()
          Returns the request URI without its context.
 boolean getRunAsSystem()
          Returns true if all calls are done without permission checks for the time beeing.
 java.lang.String getServer()
          Returns the full server URL including the port for this request, e.g.
 java.lang.String getServerName()
          Returns the name of the server handling this request, e.g.
 int getServerPort()
          Returns the port of the server handling this request, e.g.
 java.lang.String getSessionId()
          Returns the session id, which is unique at call time
 UserTicket getTicket()
           
static UserTicket getTicketFromEJB(javax.servlet.http.HttpSession session)
          Gets the user ticket from the ejb layer, and stores it in the session as 'last used user ticket'
 boolean getTreeWasModified()
          Returns true if the tree was modified within this thread by the user belonging to this thread.
static UserTicket getUserTicket()
          Returns the user ticket associated to the current thread.
 boolean isGlobalAuthenticated()
          Return true if the user successfully authenticated for the global configuration area
 boolean isGlobalConfigDivision()
          Returns true if the division is the global configuration division.
 boolean isTestDivision()
          Return true if the current context runs in the test division.
 boolean isWebDAV()
          Returns true if this request is triggered by a webdav operation.
 void login(java.lang.String loginname, java.lang.String password, boolean takeOver)
          Tries to login a user.
 void logout()
          Logout of the current user.
 void overrideTicket(UserTicket ticket)
          Override the used ticket.
static void replace(FxContext context)
          Replace the threadlocal context with another one.
 void runAsSystem()
          Runs all further calls as SYSTEM user with full permissions until stopRunAsSystem gets called.
 void setContextPath(java.lang.String contextPath)
          Changes the context path (Currently needed for embedded container testing.)
 void setDivisionId(int division)
          Changes the divison ID.
 void setGlobalAuthenticated(boolean globalAuthenticated)
          Authorize the user for the global configuration area
protected static void setLastUserTicket(javax.servlet.http.HttpSession session, UserTicket lastUserTicket)
           
 void setNodeId(long nodeId)
          Set the current users active tree node id (CMS extension)
 void setSessionID(java.lang.String sessionID)
          Sets the session ID.
 void setTicket(UserTicket ticket)
           
 void setTreeWasModified()
          Flag the tree as modified
 void stopRunAsSystem()
          Removes one runeAsSystem flag from the stack.
static FxContext storeInfos(javax.servlet.http.HttpServletRequest request, boolean dynamicContent, int divisionId, boolean isWebdav)
          Stores the needed informations about the sessions.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DIV_GLOBAL_CONFIGURATION

public static final int DIV_GLOBAL_CONFIGURATION
Global division id

See Also:
Constant Field Values

DIV_UNDEFINED

public static final int DIV_UNDEFINED
Undefined division id

See Also:
Constant Field Values

ADMIN_AUTHENTICATED

public static final java.lang.String ADMIN_AUTHENTICATED
Session key set if the user successfully logged into the admin area

See Also:
Constant Field Values

SESSION_DIVISIONID

public static final java.lang.String SESSION_DIVISIONID
Session key for the session division ID.

See Also:
Constant Field Values
Method Detail

getLastUserTicket

protected static UserTicket getLastUserTicket(javax.servlet.http.HttpSession session)

setLastUserTicket

protected static void setLastUserTicket(javax.servlet.http.HttpSession session,
                                        UserTicket lastUserTicket)

getTicket

public UserTicket getTicket()

setTicket

public void setTicket(UserTicket ticket)

getNodeId

public long getNodeId()
Get the current users active tree node id (CMS extension)

Returns:
the current users active tree node id

setNodeId

public void setNodeId(long nodeId)
Set the current users active tree node id (CMS extension)

Parameters:
nodeId - active tree node id

getTreeWasModified

public boolean getTreeWasModified()
Returns true if the tree was modified within this thread by the user belonging to this thread.

Returns:
true if the tree was modified

setTreeWasModified

public void setTreeWasModified()
Flag the tree as modified


getLocale

public java.util.Locale getLocale()
Get the current users preferred locale (based on his preferred language)

Returns:
the current users preferred locale (based on his preferred language)

getLanguage

public FxLanguage getLanguage()
Get the current users preferred language

Returns:
the current users preferred language

login

public void login(java.lang.String loginname,
                  java.lang.String password,
                  boolean takeOver)
           throws FxLoginFailedException,
                  FxAccountInUseException
Tries to login a user.

The next getUserTicket() call will return the new ticket.

Parameters:
loginname - the unique user name
password - the password
takeOver - the take over flag
Throws:
FxLoginFailedException - if the login failed
FxAccountInUseException - if take over was false and the account is in use

logout

public void logout()
            throws FxLogoutFailedException
Logout of the current user.

Throws:
FxLogoutFailedException - if the function fails

overrideTicket

public void overrideTicket(UserTicket ticket)
Override the used ticket. Please do not use this method! Its only purpose is to feed FxContext with a UserTicket when no user is logged in - ie during system startup

Parameters:
ticket - ticket to override with

getTicketFromEJB

public static UserTicket getTicketFromEJB(javax.servlet.http.HttpSession session)
Gets the user ticket from the ejb layer, and stores it in the session as 'last used user ticket'

Parameters:
session - the session
Returns:
the user ticket

isGlobalConfigDivision

public boolean isGlobalConfigDivision()
Returns true if the division is the global configuration division.

Returns:
true if the division is the global configuration division

isTestDivision

public boolean isTestDivision()
Return true if the current context runs in the test division.

Returns:
true if the current context runs in the test division.

getDivisionId

public int getDivisionId()
Returns the id of the division.

Returns:
the id of the division.

setDivisionId

public void setDivisionId(int division)
Changes the divison ID. Use with care! (Currently needed for embedded container testing.)

Parameters:
division - the division id

setContextPath

public void setContextPath(java.lang.String contextPath)
Changes the context path (Currently needed for embedded container testing.)

Parameters:
contextPath - the context path

runAsSystem

public void runAsSystem()
Runs all further calls as SYSTEM user with full permissions until stopRunAsSystem gets called. Multiple calls to this function get stacked and the runAsSystem flag is only removed when the stack is empty.


stopRunAsSystem

public void stopRunAsSystem()
Removes one runeAsSystem flag from the stack.


getRunAsSystem

public boolean getRunAsSystem()
Returns true if all calls are done without permission checks for the time beeing.

Returns:
true if all calls are done without permission checks for the time beeing

getSessionId

public java.lang.String getSessionId()
Returns the session id, which is unique at call time

Returns:
the session's id

setSessionID

public void setSessionID(java.lang.String sessionID)
Sets the session ID.

Parameters:
sessionID - the new session ID

getRequestURI

public java.lang.String getRequestURI()
Returns the request URI.

This URI contains the context path, use getRelativeRequestURI() to retrieve the path without it.

Returns:
the request URI

getRelativeRequestURI

public java.lang.String getRelativeRequestURI()
Returns the decoded relative request URI.

This function is the same as calling getRelativeRequestURI(true).

Returns:
the URI without its context path

getRelativeRequestURI

public java.lang.String getRelativeRequestURI(boolean decode)
Returns the relative request URI.

Parameters:
decode - if set to true the URI will be decoded (eg "%20" to a space), using UTF-8
Returns:
the URI without its context path

getServerName

public java.lang.String getServerName()
Returns the name of the server handling this request, e.g. www.flexive.com

Returns:
the name of the server handling this request, e.g. www.flexive.com

getServerPort

public int getServerPort()
Returns the port of the server handling this request, e.g. 80

Returns:
the port of the server handling this request, e.g. 80

getServer

public java.lang.String getServer()
Returns the full server URL including the port for this request, e.g. http://www.flexive.com:8080

Returns:
the full server URL including the port for this request, e.g. http://www.flexive.com:8080

getRemoteHost

public java.lang.String getRemoteHost()
Returns the calling remote host.

Returns:
the remote host.

getApplicationId

public java.lang.String getApplicationId()
Returns the id of the appication the request was made in.

In webapps the application id equals the context path

Returns:
the id of the appication the request was made in.

getAbsolutePath

public java.lang.String getAbsolutePath(java.lang.String path)
Returns the absolute path for the given resource (i.e. the application name + the path).

Parameters:
path - the path of the resource (e.g. /pub/css/demo.css)
Returns:
the absolute path for the given resource

get

public static FxContext get()
Gets the session information for the running thread

Returns:
the session information for the running thread

getUserTicket

public static UserTicket getUserTicket()
Returns the user ticket associated to the current thread.

Returns:
the user ticket associated to the current thread.

replace

public static void replace(FxContext context)
Replace the threadlocal context with another one. This method provides a mean to escalate the current context to other threads. As a safeguard, the context can only be replaced if the current UserTicket is null

Parameters:
context - the FxContext to use as replacement

_getEJBContext

public static FxContext _getEJBContext(FxContext template)
Get a FxContext instance to use at the EJB layer. The returned context is a guest user only! This method should only be used internally (for use in different threads, etc.)

Parameters:
template - the template to use for the division
Returns:
FxContext

_reloadUserTicket

public void _reloadUserTicket()
Reload the UserTicket, needed i.e. when language settings change


isWebDAV

public boolean isWebDAV()
Returns true if this request is triggered by a webdav operation.

Returns:
true if this request is triggered by a webdav operation

isGlobalAuthenticated

public boolean isGlobalAuthenticated()
Return true if the user successfully authenticated for the global configuration area

Returns:
true if the user successfully authenticated for the global configuration

setGlobalAuthenticated

public void setGlobalAuthenticated(boolean globalAuthenticated)
Authorize the user for the global configuration area

Parameters:
globalAuthenticated - true if the user should be authorized for the global configuration

getRequestUriNoContext

public java.lang.String getRequestUriNoContext()
Returns the request URI without its context.

Returns:
the request URI without its context.

getContextPath

public java.lang.String getContextPath()
Return the context path of this request.

Returns:
the context path of this request.

storeInfos

public static FxContext storeInfos(javax.servlet.http.HttpServletRequest request,
                                   boolean dynamicContent,
                                   int divisionId,
                                   boolean isWebdav)
Stores the needed informations about the sessions.

Parameters:
request - the users request
dynamicContent - is the content dynamic?
divisionId - the division id
isWebdav - true if this is an webdav request
Returns:
FxContext

cleanup

public static void cleanup()
Performs a cleanup of the stored informations.


toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.