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:
- 12.4
- Author:
- Luke
-
Nested Class Summary
Nested classes/interfaces inherited from class ConnectionContext
ConnectionContext.ConnectionPoolException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final jakarta.servlet.http.HttpServletRequestThe HTTP request.protected final jakarta.servlet.http.HttpServletResponseThe HTTP response.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionHTTPContext(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse rsp) Creates a new Command context from an HTTP Servlet Request/Resposne pair. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCookie(jakarta.servlet.http.Cookie c) Adds a Cookie to the response.voidclearCookie(String name) Clears a Cookie in the response.getCmdParameter(int prmType, Object defaultValue) Returns one of the special command parameters.jakarta.servlet.http.CookieReturns 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.jakarta.servlet.http.HttpServletRequestReturns the current HTTP Servlet Request.jakarta.servlet.http.HttpServletResponseReturns the current HTTP Servlet Response.getRoles()Returns the list of roles for the user.jakarta.servlet.http.HttpSessionReturns the current HTTP session.getUser()Returns the authenticated user object.booleanReturns if this command is being invoked by an authenticated user.booleanReturns whether an Administrator is impersonating another user.booleanisUserInRole(String roleName) Returns if the currently logged in user is a member of a particular role.booleanReturns whether the user has passed CAPTCHA validation.voidsetAttribute(String name, Object value, Command.Scope scope) Sets an attribute in a particular context.voidsetExpiry(int expireInterval) Sets an Expires header on the response.voidHelper method to set a numeric response header.voidHelper method to set a response header.voidUpdates the User executing this operation.Methods inherited from class 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:
-
CSP_ATTR_NAME
- See Also:
-
_req
protected final jakarta.servlet.http.HttpServletRequest _reqThe HTTP request. -
_rsp
protected final jakarta.servlet.http.HttpServletResponse _rspThe HTTP response.
-
-
Constructor Details
-
HTTPContext
public HTTPContext(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse rsp) Creates a new Command context from an HTTP Servlet Request/Resposne pair.- Parameters:
req- the Servlet Requestrsp- the Servlet Response
-
-
Method Details
-
getSession
public jakarta.servlet.http.HttpSession getSession()Returns the current HTTP session.- Returns:
- the HTTP session, null if none present or invalid
-
getRequest
public jakarta.servlet.http.HttpServletRequest getRequest()Returns the current HTTP Servlet Request.- Specified by:
getRequestin interfaceSecurityContext- Returns:
- the Servlet Request
-
getResponse
public jakarta.servlet.http.HttpServletResponse getResponse()Returns the current HTTP Servlet Response.- Returns:
- the Servlet Response
-
getUser
Returns the authenticated user object.- Specified by:
getUserin 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:
isAuthenticatedin 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:
getRolesin 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:
isUserInRolein 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
Returns an HTTP cookie.- Parameters:
name- the cookie name- Returns:
- the cookie, or null if not found
-
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
public void addCookie(jakarta.servlet.http.Cookie c) Adds a Cookie to the response.- Parameters:
c- the Cookie
-
clearCookie
Clears a Cookie in the response.- Parameters:
name- the Cookie name
-
getCmdParameter
-