Class JEEContext

  • All Implemented Interfaces:
    org.pac4j.core.context.WebContext

    public class JEEContext
    extends java.lang.Object
    implements org.pac4j.core.context.WebContext
    This implementation uses the JEE HttpServletRequest and HttpServletResponse.
    Since:
    1.4.0
    Author:
    Jerome Leleu
    • Constructor Summary

      Constructors 
      Constructor Description
      JEEContext​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Build a JEE context from the current HTTP request and response.
    • Constructor Detail

      • JEEContext

        public JEEContext​(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
        Build a JEE context from the current HTTP request and response.
        Parameters:
        request - the current request
        response - the current response
    • Method Detail

      • getRequestParameter

        public java.util.Optional<java.lang.String> getRequestParameter​(java.lang.String name)
        Specified by:
        getRequestParameter in interface org.pac4j.core.context.WebContext
      • getRequestAttribute

        public java.util.Optional getRequestAttribute​(java.lang.String name)
        Specified by:
        getRequestAttribute in interface org.pac4j.core.context.WebContext
      • setRequestAttribute

        public void setRequestAttribute​(java.lang.String name,
                                        java.lang.Object value)
        Specified by:
        setRequestAttribute in interface org.pac4j.core.context.WebContext
      • getRequestParameters

        public java.util.Map<java.lang.String,​java.lang.String[]> getRequestParameters()
        Specified by:
        getRequestParameters in interface org.pac4j.core.context.WebContext
      • getRequestHeader

        public java.util.Optional<java.lang.String> getRequestHeader​(java.lang.String name)
        Specified by:
        getRequestHeader in interface org.pac4j.core.context.WebContext
      • getRequestMethod

        public java.lang.String getRequestMethod()
        Specified by:
        getRequestMethod in interface org.pac4j.core.context.WebContext
      • getRemoteAddr

        public java.lang.String getRemoteAddr()
        Specified by:
        getRemoteAddr in interface org.pac4j.core.context.WebContext
      • getNativeRequest

        public javax.servlet.http.HttpServletRequest getNativeRequest()
        Return the native HTTP request.
        Returns:
        the native HTTP request
      • getNativeResponse

        public javax.servlet.http.HttpServletResponse getNativeResponse()
        Return the native HTTP response.
        Returns:
        the native HTTP response
      • setResponseHeader

        public void setResponseHeader​(java.lang.String name,
                                      java.lang.String value)
        Specified by:
        setResponseHeader in interface org.pac4j.core.context.WebContext
      • getResponseHeader

        public java.util.Optional<java.lang.String> getResponseHeader​(java.lang.String name)
        Specified by:
        getResponseHeader in interface org.pac4j.core.context.WebContext
      • setResponseContentType

        public void setResponseContentType​(java.lang.String content)
        Specified by:
        setResponseContentType in interface org.pac4j.core.context.WebContext
      • getServerName

        public java.lang.String getServerName()
        Specified by:
        getServerName in interface org.pac4j.core.context.WebContext
      • getServerPort

        public int getServerPort()
        Specified by:
        getServerPort in interface org.pac4j.core.context.WebContext
      • getScheme

        public java.lang.String getScheme()
        Specified by:
        getScheme in interface org.pac4j.core.context.WebContext
      • isSecure

        public boolean isSecure()
        Specified by:
        isSecure in interface org.pac4j.core.context.WebContext
      • getRequestURL

        public java.lang.String getRequestURL()
        Specified by:
        getRequestURL in interface org.pac4j.core.context.WebContext
      • getFullRequestURL

        public java.lang.String getFullRequestURL()
        Specified by:
        getFullRequestURL in interface org.pac4j.core.context.WebContext
      • getRequestCookies

        public java.util.Collection<org.pac4j.core.context.Cookie> getRequestCookies()
        Specified by:
        getRequestCookies in interface org.pac4j.core.context.WebContext
      • addResponseCookie

        public void addResponseCookie​(org.pac4j.core.context.Cookie cookie)
        Specified by:
        addResponseCookie in interface org.pac4j.core.context.WebContext
      • getPath

        public java.lang.String getPath()
        This is not implemented using HttpServletRequest.getServletPath() or HttpServletRequest.getPathInfo() because they both have strange behaviours in different contexts (inside servlets, inside filters, various container implementation, etc)
        Specified by:
        getPath in interface org.pac4j.core.context.WebContext
      • getRequestContent

        public java.lang.String getRequestContent()
        Specified by:
        getRequestContent in interface org.pac4j.core.context.WebContext
      • getProtocol

        public java.lang.String getProtocol()
        Specified by:
        getProtocol in interface org.pac4j.core.context.WebContext