Class SessionEncodeURL


  • public class SessionEncodeURL
    extends Object
    SessionEncodeURL class encodes the URL with the cookie value as a query string or extra path info based on the encoding scheme.

    The cookie Value is written in the URL based on the encoding scheme specified. The Cookie Value could be written as path info separated by either a "/" OR ";" or as a query string.

    If the encoding scheme is SLASH then the cookie value would be written in the URL as extra path info in the following format: protocol://server:port/servletpath/<cookieName>=<cookieValue>? queryString

    Note that this format works only if the path is a servlet, if a a JSP file is specified then web containers return with "File Not found" error. To rewrite links which are JSP files with cookie value use the SEMICOLON or QUERY encoding scheme.

    If the encoding scheme is SEMICOLON then the cookie value would be written in the URL as extra path info in the following format: protocol://server:port/path;<cookieName=cookieValue> ?queryString Note that this is not supported in the servlet specification and some web containers do not support this.

    If the encoding scheme is QUERY then the cookie value would be written in the URL in the following format:

     protocol://server:port/path?<cookieName>=<cookieValue>
     protocol://server:port/path?queryString&<cookieName>=<cookieValue>
     

    This is the default and OpenAM always encodes in this format unless otherwise specified. If the URL passed in has query parameter then entity escaping of ampersand will be done before appending the cookie if the escape is true. Only the ampersand before appending cookie parameter will be entity escaped.

    • Constructor Detail

      • SessionEncodeURL

        public SessionEncodeURL()
        Constructs SessionEncodeURL
    • Method Detail

      • encodeURL

        public static String encodeURL​(String sidString,
                                       String url,
                                       short encodingScheme,
                                       boolean escape)
        Encodes the URL with the cookie value as a query string or extra path info based on the encoding scheme. if encoding scheme is QUERY , encoded URL format will be : protocol://server:port/path?cookieName=cookieValue if escape is false then no entity escaping of ampersand.
         protocol://server:port/path?queryString&
                 cookieName=cookieValue
         
        if escape is true then entity escaping of ampersand
         protocol://server:port/path?queryString&cookieName=cookieValue
         

        if encoding scheme is SLASH, encodedURL format will be : protocol://server:port/path/cookieName=cookieValue

        if encoding scheme is SEMICOLON, encodedURL format will be: protocol://server:port/path;cookieName=cookieValue

        Parameters:
        sidString - Session ID.
        url - the URL to be encoded.
        encodingScheme - how the cookie will be encoded in as query string or as extra path info (SLASH or SEMICOLON)
        escape - true to escape ampersand.
        Returns:
        the URL encoded with the session ID.
      • getSidFromURL

        public static String getSidFromURL​(jakarta.servlet.http.HttpServletRequest request)
        Checks whether the encoded URL has session id or not. And then extracts the Session Id from it.
        Parameters:
        request - , HTTPServletRequestObject
        Returns:
        the extracted SessionID
      • getSidFromURL

        public static String getSidFromURL​(jakarta.servlet.http.HttpServletRequest request,
                                           String cookieName)
        Checks whether the encoded URL has session id or not. And then extracts the Session Id from it.
        Parameters:
        request - HTTP Servlet Request.
        cookieName - Cookie name.
        Returns:
        the extracted Session ID
      • buildCookieString

        public static String buildCookieString​(String url,
                                               String cookieStr,
                                               short encodingScheme,
                                               boolean escape)
        Constructs the cookie string based on the URL and cookie String passed.
        Parameters:
        url - URL which needs to be rewritten.
        cookieStr - Cookie name and cookie value.
        encodingScheme - how the cookie will be encoded in as query string or as extra path info (SLASH or SEMICOLON).
        escape - true to escape ampersand.
        Returns:
        encoded URL.
      • createCookieString

        public static String createCookieString​(String cookieName,
                                                String sessionID)