Class ClientContext

  • All Implemented Interfaces:
    Context

    public final class ClientContext
    extends AbstractContext
    Client context gives easy access to client-related information that are available into the request. Supported data includes:
    • Remote IP address
    • Remote port
    • Username
    • Client provided certificates
    • User-Agent information
    • Whether the client is external
    • Whether the connection to the client is secure
    • Local port
    • Local address
    • Constructor Detail

      • ClientContext

        public ClientContext​(JsonValue savedContext,
                             ClassLoader classLoader)
        Restore from JSON representation.
        Parameters:
        savedContext - The JSON representation from which this context's attributes should be parsed.
        classLoader - The ClassLoader which can properly resolve the persisted class-name.
    • Method Detail

      • newInternalClientContext

        public static ClientContext newInternalClientContext​(Context parent)
        Creates an internal ClientContext instance. All data related to external context (e.g remote address, user agent...) will be set with empty non null values. The returned internal ClientContext is considered as secure.
        Parameters:
        parent - The parent context.
        Returns:
        An internal ClientContext instance.
      • getRemoteUser

        public String getRemoteUser()
        Returns the login of the user making this request or an empty string if not known.
        Returns:
        the login of the user making this request or an empty string if not known.
      • getRemoteAddress

        public String getRemoteAddress()
        Returns the IP address of the client (or last proxy) that sent the request or an empty string if the client is internal.
        Returns:
        the IP address of the client (or last proxy) that sent the request or an empty string if the client is internal.
      • getRemotePort

        public int getRemotePort()
        Returns the source port of the client (or last proxy) that sent the request or -1 if the client is internal.
        Returns:
        the source port of the client (or last proxy) that sent the request or -1 if the client is internal.
      • getCertificates

        public Collection<? extends Certificate> getCertificates()
        Returns the collection (possibly empty) of certificate(s) provided by the client. If no certificates are available, an empty list is returned.
        Returns:
        the collection (possibly empty) of certificate(s) provided by the client.
      • getUserAgent

        public String getUserAgent()
        Returns the value of the User-Agent HTTP Header (if any, returns an empty string otherwise).
        Returns:
        the value of the User-Agent HTTP Header (if any, returns an empty string otherwise).
      • isExternal

        public boolean isExternal()
        Returns true if this client is external.
        Returns:
        true if this client is external.
      • isSecure

        public boolean isSecure()
        Returns true if this client connection is secure. It is the responsibility to the underlying protocol/implementation to determine whether or not the connection is secure. For example HTTPS and internal connections are meant to be secure.
        Returns:
        true if this client connection is secure.
      • getLocalAddress

        public String getLocalAddress()
        Returns the IP address of the interface that received the request.
        Returns:
        the IP address of the server that received the request.
      • getLocalPort

        public int getLocalPort()
        Returns the port of the interface that received the request.
        Returns:
        the port of the interface that received the request.