public class

CookieUtils

extends Object
java.lang.Object
   ↳ com.atlassian.jira.web.util.CookieUtils

Class Overview

This class handles utility methods for managing HTTP cookies.

Summary

Constants
String JSESSIONID session id cookie name
Public Constructors
CookieUtils()
Public Methods
static String cookiePathFor(HttpServletRequest httpServletRequest)
Get path for newly created cookie.
static Cookie createConglomerateCookie(String cookieName, Map<StringString> map, HttpServletRequest request)
static Cookie createCookie(String name, String value, HttpServletRequest currentRequest)
Creat cookie with path reflecting the context path of currentRequest.
static String getCookieValue(String cookieName, HttpServletRequest currentRequest)
Get value of cookie with given cookieName from currentRequest, or null, if the request does not have such cookie.
static String getSingleSessionId(Cookie[] cookies)
Gets the session id as a string from the given array of Cookie objects if only one JSESSIONID cookie is found.
static boolean hasSessionId(Cookie[] cookies)
Returns true if one or more cookies with name of JSESSIONID is found.
static Map<StringString> parseConglomerateCookie(String cookieName, HttpServletRequest currentRequest)
Parse the key/value pairs out of a conglomerate cookie.
static void setSessionCookie(HttpServletRequest request, HttpServletResponse response, String sessionId)
Adds a new JSESSIONID cookie to the HTTP response if the given sessionId is not null.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String JSESSIONID

session id cookie name

Constant Value: "JSESSIONID"

Public Constructors

public CookieUtils ()

Public Methods

public static String cookiePathFor (HttpServletRequest httpServletRequest)

Get path for newly created cookie.

Parameters
httpServletRequest current request
Returns
  • cookie path reflecting the current request's path

public static Cookie createConglomerateCookie (String cookieName, Map<StringString> map, HttpServletRequest request)

public static Cookie createCookie (String name, String value, HttpServletRequest currentRequest)

Creat cookie with path reflecting the context path of currentRequest.

Parameters
name new cookie's name
value new cookie's value
currentRequest current request
Returns
  • new cookie

public static String getCookieValue (String cookieName, HttpServletRequest currentRequest)

Get value of cookie with given cookieName from currentRequest, or null, if the request does not have such cookie.

Parameters
cookieName name of the cookie to retrieve
currentRequest current request
Returns
  • value of the cookie, or null, if no cookie with such name exists

public static String getSingleSessionId (Cookie[] cookies)

Gets the session id as a string from the given array of Cookie objects if only one JSESSIONID cookie is found. If none or more than one JSESSIONID cookies are found, returns null.

Parameters
cookies the cookies.
Returns
  • session value if unique one is found.

public static boolean hasSessionId (Cookie[] cookies)

Returns true if one or more cookies with name of JSESSIONID is found.

Parameters
cookies an array of Cookie objects
Returns
  • true if one or more sessionid cookies are found

public static Map<StringString> parseConglomerateCookie (String cookieName, HttpServletRequest currentRequest)

Parse the key/value pairs out of a conglomerate cookie.

The returned map will not contain empty values (zero length strings: they are discarded).

Parameters
cookieName the name of the cookie
currentRequest current request
Returns
  • the non-null map of key/value pairs

public static void setSessionCookie (HttpServletRequest request, HttpServletResponse response, String sessionId)

Adds a new JSESSIONID cookie to the HTTP response if the given sessionId is not null. No cookie is set if given sessionId is null.

Parameters
request HTTP request
response HTTP response
sessionId session ID to set as a value of the cookie