Enum Class ResponseCookie.SameSite
- All Implemented Interfaces:
Serializable
,Comparable<ResponseCookie.SameSite>
,Constable
- Enclosing class:
ResponseCookie
Values which control whether or not a response cookie is sent with cross-site requests, providing some protection against cross-site request forgery attacks (CSRF).
See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value for details.
- Author:
- Mark Allen
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionMeans that the cookie is not sent on cross-site requests, such as on requests to load images or frames, but is sent when a user is navigating to the origin site from an external site (for example, when following a link).Means that the browser sends the cookie with both cross-site and same-site requests.Means that the browser sends the cookie only for same-site requests, that is, requests originating from the same site that set the cookie. -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional
<ResponseCookie.SameSite> fromHeaderRepresentation
(String headerRepresentation) Returns theResponseCookie.SameSite
enum value that matches the correspondingSameSite
response header value representation (one ofStrict
,Lax
, orNone
- case-insensitive).The HTTP header value that corresponds to this enum value - one ofStrict
,Lax
, orNone
.static ResponseCookie.SameSite
Returns the enum constant of this class with the specified name.static ResponseCookie.SameSite[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.Methods inherited from class java.lang.Enum
compareTo, describeConstable, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
-
Enum Constant Details
-
STRICT
Means that the browser sends the cookie only for same-site requests, that is, requests originating from the same site that set the cookie. If a request originates from a different domain or scheme (even with the same domain), no cookies with theSameSite=Strict
attribute are sent. -
LAX
Means that the cookie is not sent on cross-site requests, such as on requests to load images or frames, but is sent when a user is navigating to the origin site from an external site (for example, when following a link). This is the default behavior if theSameSite
attribute is not specified. -
NONE
Means that the browser sends the cookie with both cross-site and same-site requests. TheSecure
attribute must also be set when setting this value, like soSameSite=None; Secure
. IfSecure
is missing, an error will be logged.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
fromHeaderRepresentation
@Nonnull public static Optional<ResponseCookie.SameSite> fromHeaderRepresentation(@Nonnull String headerRepresentation) Returns theResponseCookie.SameSite
enum value that matches the correspondingSameSite
response header value representation (one ofStrict
,Lax
, orNone
- case-insensitive).- Parameters:
headerRepresentation
- a case-insensitive HTTP header value - one ofStrict
,Lax
, orNone
- Returns:
- the enum value that corresponds to the given the header representation, or
Optional.empty()
if none matches
-
getHeaderRepresentation
The HTTP header value that corresponds to this enum value - one ofStrict
,Lax
, orNone
.- Returns:
- the HTTP header value for this enum
-