Class HTTPContext

java.lang.Object
org.deltava.jdbc.ConnectionContext
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:
11.6
Author:
Luke
  • Field Details

  • Constructor Details

    • 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 Details

    • 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 Pilot getUser()
      Returns the authenticated user object.
      Specified by:
      getUser in interface SecurityContext
      Returns:
      the User object, or null if anonymous
      See Also:
    • setUser

      public void setUser(Pilot 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:
    • 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:
    • 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, Collection<String> deflt)
      Returns the values of a collection of request parameters.
      Parameters:
      pName - the parameter name
      deflt - the default value if the parameter is null
      Returns:
      a Collection parameter values, or the default value 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, int maxSize) throws CommandException
      Returns the value of an uploaded file object.
      Parameters:
      name - the file name
      maxSize - 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

      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:
    • setExpiry

      public void setExpiry(int expireInterval)
      Sets an Expires header on the response.
      Parameters:
      expireInterval - the expiry time in seconds
    • setHeader

      public void setHeader(String name, String value)
      Helper method to set a response header.
      Parameters:
      name - the header name
      value - the header value
    • setHeader

      public void setHeader(String name, int value)
      Helper method to set a numeric response header.
      Parameters:
      name - the header name
      value - the header value
    • addCookie

      public void addCookie(Cookie c)
      Adds a Cookie to the response.
      Parameters:
      c - the Cookie
    • 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: