public final class CookieBuilder extends Object
Modifier and Type | Field and Description |
---|---|
static int |
COOKIE_APPROX_BROWSER_LIMIT
Browse cookie size limit.
|
Modifier and Type | Method and Description |
---|---|
Cookie |
build()
Create a
Cookie based on the details held in this CookieBuilder . |
static CookieBuilder |
builder(JsonValue cookieConfig,
String defaultName,
String defaultPath)
Create a
CookieBuilder based on the JSON structure of: |
static CookieBuilder |
builder(String name)
Create a
CookieBuilder with just the cookie name set. |
static int |
calculateCookieHeaderSize(Cookie cookie)
Convenience method to calculate the size of the
Cookie when it is turned into a header. |
CookieBuilder |
domain(String domain)
Set the domain and return a new instance of this builder.
|
String |
getName()
The name of the cookie that will be built from this
CookieBuilder . |
CookieBuilder |
httpOnly(boolean httpOnly)
Set the httpOnly flag and return a new instance of this builder.
|
CookieBuilder |
path(String path)
Set the path and return a new instance of this builder.
|
CookieBuilder |
sameSite(Cookie.SameSite sameSite)
Set the
SameSite enum and return a new instance of this builder. |
CookieBuilder |
secure(boolean secure)
Set the secure flag and return a new instance of this builder.
|
public static final int COOKIE_APPROX_BROWSER_LIMIT
public static CookieBuilder builder(JsonValue cookieConfig, String defaultName, String defaultPath)
CookieBuilder
based on the JSON structure of:
{
"name" : Name of cookie. Defaults to {@literal defaultName}.
"domain" : Domain that cookie is applicable to.
"path" : Path to apply to the cookie. Defaults to {@literal defaultPath}.
"secure" : Set to {@code true} if the cookie should be secure. Default is {@code false}.
"httpOnly" : Set to {@code true} if cookie should be httpOnly. Default is {@code true}.
"sameSite" : SameSite cookie configuration. Default is {@code null}.
}
cookieConfig
- The JSON containing the cookie details.defaultName
- The cookie name to use if not defined in the cookieConfig.defaultPath
- The cookie path to use if not defined in the cookieConfig.CookieBuilder
based on the values defined in the cookieConfig.public static CookieBuilder builder(String name)
CookieBuilder
with just the cookie name set.name
- The name to use for the cookie name.CookieBuilder
with just the cookie name set.public static int calculateCookieHeaderSize(Cookie cookie)
Cookie
when it is turned into a header.
Can be useful when dealing with JWT based cookies to check if they are going to be too big compared to the
COOKIE_APPROX_BROWSER_LIMIT.public String getName()
CookieBuilder
.CookieBuilder
.public CookieBuilder domain(String domain)
domain
- the value of domain to use.public CookieBuilder path(String path)
path
- the value of path to use.public CookieBuilder secure(boolean secure)
secure
- true
if secure cookies should be enabled or false
otherwise.public CookieBuilder httpOnly(boolean httpOnly)
httpOnly
- true
if httpOnly cookies should be enabled or false
otherwise.public CookieBuilder sameSite(Cookie.SameSite sameSite)
SameSite
enum and return a new instance of this builder.sameSite
- LAX
or STRICT
.public Cookie build()
Cookie
based on the details held in this CookieBuilder
.Cookie
based on the details held in this CookieBuilder
.Copyright 2011-2017 ForgeRock AS.