Class HTTPContext
java.lang.Object
org.deltava.jdbc.ConnectionContext
org.deltava.commands.HTTPContext
- All Implemented Interfaces:
SecurityContext
- Direct Known Subclasses:
CommandContext
,ServiceContext
An abstract class to share command data between different HTTP command contexts.
- Since:
- 2.4
- Version:
- 11.6
- Author:
- Luke
-
Nested Class Summary
Nested classes/interfaces inherited from class org.deltava.jdbc.ConnectionContext
ConnectionContext.ConnectionPoolException
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final HttpServletRequest
The HTTP request.protected final HttpServletResponse
The HTTP response.static final String
static final String
static final String
static final String
static final String
static final String
static final String
-
Constructor Summary
ConstructorsConstructorDescriptionHTTPContext
(HttpServletRequest req, HttpServletResponse rsp) Creates a new Command context from an HTTP Servlet Request/Resposne pair. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a Cookie to the response.getCmdParameter
(int prmType, Object defaultValue) Returns one of the special command parameters.Returns an HTTP cookie.Returns the value of an uploaded file object.getParameter
(String pName) Returns the value of a request parameter.getParameters
(String pName) Returns the values of a collection of request parameters.getParameters
(String pName, Collection<String> deflt) Returns the values of a collection of request parameters.Returns the current HTTP Servlet Request.Returns the current HTTP Servlet Response.getRoles()
Returns the list of roles for the user.Returns the current HTTP session.getUser()
Returns the authenticated user object.boolean
Returns if this command is being invoked by an authenticated user.boolean
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.boolean
Returns whether the user has passed CAPTCHA validation.void
setAttribute
(String name, Object value, Command.Scope scope) Sets an attribute in a particular context.void
setExpiry
(int expireInterval) Sets an Expires header on the response.void
Helper method to set a numeric response header.void
Helper method to set a response header.void
Updates the User executing this operation.Methods inherited from class org.deltava.jdbc.ConnectionContext
commitTX, getConnection, getDB, hasConnection, release, rollbackTX, setDB, startTX
-
Field Details
-
ADDRINFO_ATTR_NAME
- See Also:
-
USER_ATTR_NAME
- See Also:
-
SU_ATTR_NAME
- See Also:
-
USERAGENT_ATTR_NAME
- See Also:
-
HTTPCTXT_ATTR_NAME
- See Also:
-
CAPTCHA_ATTR_NAME
- See Also:
-
RTLIMIT_ATTR_NAME
- See Also:
-
_req
The HTTP request. -
_rsp
The HTTP response.
-
-
Constructor Details
-
HTTPContext
Creates a new Command context from an HTTP Servlet Request/Resposne pair.- Parameters:
req
- the Servlet Requestrsp
- the Servlet Response
-
-
Method Details
-
getSession
Returns the current HTTP session.- Returns:
- the HTTP session, null if none present or invalid
-
getRequest
Returns the current HTTP Servlet Request.- Specified by:
getRequest
in interfaceSecurityContext
- Returns:
- the Servlet Request
-
getResponse
Returns the current HTTP Servlet Response.- Returns:
- the Servlet Response
-
getUser
Returns the authenticated user object.- Specified by:
getUser
in interfaceSecurityContext
- Returns:
- the User object, or null if anonymous
- See Also:
-
setUser
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 interfaceSecurityContext
- Returns:
- TRUE if the user is logged in, FALSE otherwise
- See Also:
-
isSuperUser
public boolean isSuperUser()Returns whether an Administrator is impersonating another user.- Returns:
- TRUE if superuser mode is on, otherwise FALSE
-
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 interfaceSecurityContext
- Returns:
- a Collection of role names
- See Also:
-
isUserInRole
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'sHttpServletRequest.isUserInRole(String)
method, which may be overriden by a custom request handler.- Specified by:
isUserInRole
in interfaceSecurityContext
- Parameters:
roleName
- the role name- Returns:
- TRUE if the user is a member of the specified role, otherwise FALSE
-
getParameter
-
getParameters
Returns the values of a collection of request parameters.- Parameters:
pName
- the parameter namedeflt
- the default value if the parameter is null- Returns:
- a Collection parameter values, or the default value if not present
-
getParameters
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
Returns the value of an uploaded file object.- Parameters:
name
- the file namemaxSize
- the maximum size in bytes, or zero to ignore size- Returns:
- the file data, or null if not found
- Throws:
CommandException
- if the file size exceeds the maximum size
-
passedCAPTCHA
public boolean passedCAPTCHA()Returns whether the user has passed CAPTCHA validation.- Returns:
- TRUE if the user has passed the CAPTCHA, otherwise FALSE
-
getCookie
-
setAttribute
Sets an attribute in a particular context.- Parameters:
name
- the name of the attributevalue
- the attribute valuescope
- the scope (application, session or request)- See Also:
-
setExpiry
public void setExpiry(int expireInterval) Sets an Expires header on the response.- Parameters:
expireInterval
- the expiry time in seconds
-
setHeader
-
setHeader
Helper method to set a numeric response header.- Parameters:
name
- the header namevalue
- the header value
-
addCookie
-
getCmdParameter
-