org.deltava.commands
Class HTTPContext

java.lang.Object
  extended by org.deltava.jdbc.ConnectionContext
      extended by org.deltava.commands.HTTPContext
All Implemented Interfaces:
SecurityContext
Direct Known Subclasses:
CommandContext, ServiceContext

public abstract class HTTPContext
extends ConnectionContext
implements SecurityContext

An abstract class to share command data between different HTTP command contexts.

Since:
2.4
Version:
2.5
Author:
Luke

Nested Class Summary
 
Nested classes/interfaces inherited from class org.deltava.jdbc.ConnectionContext
ConnectionContext.ConnectionPoolException
 
Field Summary
static String ADDRINFO_ATTR_NAME
           
static String SU_ATTR_NAME
           
static String USER_ATTR_NAME
           
 
Constructor Summary
HTTPContext(HttpServletRequest req, HttpServletResponse rsp)
          Creates a new Command context from an HTTP Servlet Request/Resposne pair.
 
Method Summary
 Object getCmdParameter(int prmType, Object defaultValue)
          Returns one of the special command parameters.
 Cookie getCookie(String name)
          Returns an HTTP cookie.
 FileUpload getFile(String name)
          Returns the value of an uploaded file object.
 String getParameter(String pName)
          Returns the value of a request parameter.
 Collection<String> getParameters(String pName)
          Returns the values of a collection of request parameters.
 HttpServletRequest getRequest()
          Returns the current HTTP Servlet Request.
 HttpServletResponse getResponse()
          Returns the current HTTP Servlet Response.
 Collection<String> getRoles()
          Returns the list of roles for the user.
 HttpSession getSession()
          Returns the current HTTP session.
 Person getUser()
          Returns the authenticated user object.
 boolean isAuthenticated()
          Returns if this command is being invoked by an authenticated user.
 boolean isSuperUser()
          Returns whether an Administrator is impersonating another user.
 boolean isUserInRole(String roleName)
          Returns if the currently logged in user is a member of a particular role.
 void setAttribute(String name, Object value, Command.Scope scope)
          Sets an attribute in a particular context.
 void setUser(Person p)
          Updates the User executing this operation.
 
Methods inherited from class org.deltava.jdbc.ConnectionContext
commitTX, getConnection, release, rollbackTX, startTX
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADDRINFO_ATTR_NAME

public static final String ADDRINFO_ATTR_NAME
See Also:
Constant Field Values

USER_ATTR_NAME

public static final String USER_ATTR_NAME
See Also:
Constant Field Values

SU_ATTR_NAME

public static final String SU_ATTR_NAME
See Also:
Constant Field Values
Constructor Detail

HTTPContext

public HTTPContext(HttpServletRequest req,
                   HttpServletResponse rsp)
Creates a new Command context from an HTTP Servlet Request/Resposne pair.

Parameters:
req - the Servlet Request
rsp - the Servlet Response
Method Detail

getSession

public HttpSession getSession()
Returns the current HTTP session.

Returns:
the HTTP session, null if none present or invalid

getRequest

public HttpServletRequest getRequest()
Returns the current HTTP Servlet Request.

Specified by:
getRequest in interface SecurityContext
Returns:
the Servlet Request

getResponse

public HttpServletResponse getResponse()
Returns the current HTTP Servlet Response.

Returns:
the Servlet Response

getUser

public Person getUser()
Returns the authenticated user object.

Specified by:
getUser in interface SecurityContext
Returns:
the User object, or null if anonymous
See Also:
isAuthenticated(), isUserInRole(String)

setUser

public void setUser(Person p)
Updates the User executing this operation. This method has no effect if a user object is already present in the request.

Parameters:
p - the User object, or null if anonymous

isAuthenticated

public boolean isAuthenticated()
Returns if this command is being invoked by an authenticated user.

Specified by:
isAuthenticated in interface SecurityContext
Returns:
TRUE if the user is logged in, FALSE otherwise
See Also:
getUser(), getRoles()

isSuperUser

public boolean isSuperUser()
Returns whether an Administrator is impersonating another user.

Returns:
TRUE if superuser mode is on, otherwise FALSE

getRoles

public Collection<String> getRoles()
Returns the list of roles for the user. This will return a List with a single element ("Anonymous") if the user is not currently authenticated

Specified by:
getRoles in interface SecurityContext
Returns:
a Collection of role names
See Also:
isAuthenticated(), getUser()

isUserInRole

public boolean isUserInRole(String roleName)
Returns if the currently logged in user is a member of a particular role. Unless a specific user has been injected, this method delegates the call to the underlying HTTP servlet request's HttpServletRequest.isUserInRole(String) method, which may be overriden by a custom request handler.

Specified by:
isUserInRole in interface SecurityContext
Parameters:
roleName - the role name
Returns:
TRUE if the user is a member of the specified role, otherwise FALSE

getParameter

public String getParameter(String pName)
Returns the value of a request parameter.

Parameters:
pName - the parameter name
Returns:
the parameter value, or null if not present

getParameters

public Collection<String> getParameters(String pName)
Returns the values of a collection of request parameters.

Parameters:
pName - the parameter name
Returns:
a Collection parameter values, or null if not present

getFile

public FileUpload getFile(String name)
Returns the value of an uploaded file object.

Parameters:
name - the file name
Returns:
the file data, or null if not found

getCookie

public Cookie getCookie(String name)
Returns an HTTP cookie.

Parameters:
name - the cookie name
Returns:
the cookie, or null if not found

setAttribute

public void setAttribute(String name,
                         Object value,
                         Command.Scope scope)
Sets an attribute in a particular context.

Parameters:
name - the name of the attribute
value - the attribute value
scope - the scope (application, session or request)
See Also:
Command.REQUEST, Command.SESSION

getCmdParameter

public Object getCmdParameter(int prmType,
                              Object defaultValue)
Returns one of the special command parameters.

Parameters:
prmType - the Parameter type
defaultValue - the value to return if parameter not specified in the request
Returns:
the parameter value
See Also:
Command.ID, Command.OPERATION


Copyright © 2004-2009 Global Virtual Airlines Group. All Rights Reserved.