Package com.oorian
Class OorianCookie
java.lang.Object
com.oorian.OorianCookie
Framework-level cookie representation, decoupling from servlet API cookie classes.
This is a simple POJO that holds cookie attributes. Adapter implementations in the thin Jakarta/J2EE libraries convert between this class and the servlet API cookie.
- Since:
- 2.1
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
-
Constructor Summary
ConstructorsConstructorDescriptionOorianCookie(String name, String value) Constructs a new OorianCookie with the specified name and value. -
Method Summary
Modifier and TypeMethodDescriptionReturns the domain for which the cookie is valid.intReturns the maximum age of the cookie in seconds.getName()Returns the cookie name.getPath()Returns the path for which the cookie is valid.Returns the SameSite attribute value.getValue()Returns the cookie value.booleanReturns whether the cookie is HTTP-only.booleanisSecure()Returns whether the cookie is secure-only.voidSets the domain for which the cookie is valid.voidsetHttpOnly(boolean httpOnly) Sets whether the cookie should be inaccessible to client-side scripts.voidsetMaxAge(int maxAge) Sets the maximum age of the cookie in seconds.voidSets the cookie name.voidSets the path for which the cookie is valid.voidsetSameSite(String sameSite) Sets the SameSite attribute for the cookie.voidsetSecure(boolean secure) Sets whether the cookie should only be sent over secure (HTTPS) connections.voidSets the cookie value.
-
Constructor Details
-
OorianCookie
Constructs a new OorianCookie with the specified name and value.If secure cookie defaults have been configured via
Application.setSecureCookieDefaults(CookieDefaults), the cookie is initialized with those defaults. Otherwise, HttpOnly and Secure default tofalseand SameSite defaults tonull.- Parameters:
name- the cookie namevalue- the cookie value
-
-
Method Details
-
setName
Sets the cookie name.- Parameters:
name- the cookie name
-
setValue
Sets the cookie value.- Parameters:
value- the cookie value
-
setPath
Sets the path for which the cookie is valid.- Parameters:
path- the cookie path
-
setDomain
Sets the domain for which the cookie is valid.- Parameters:
domain- the cookie domain
-
setMaxAge
public void setMaxAge(int maxAge) Sets the maximum age of the cookie in seconds.- Parameters:
maxAge- the maximum age in seconds; -1 means session cookie
-
setSecure
public void setSecure(boolean secure) Sets whether the cookie should only be sent over secure (HTTPS) connections.- Parameters:
secure- true for secure-only cookies
-
setHttpOnly
public void setHttpOnly(boolean httpOnly) Sets whether the cookie should be inaccessible to client-side scripts.- Parameters:
httpOnly- true to prevent client-side script access
-
setSameSite
Sets the SameSite attribute for the cookie.The SameSite attribute controls whether the cookie is sent with cross-site requests, providing protection against CSRF attacks.
- Parameters:
sameSite- the SameSite value ("Strict", "Lax", or "None")
-
getName
Returns the cookie name.- Returns:
- the cookie name
-
getValue
Returns the cookie value.- Returns:
- the cookie value
-
getPath
Returns the path for which the cookie is valid.- Returns:
- the cookie path
-
getDomain
Returns the domain for which the cookie is valid.- Returns:
- the cookie domain
-
getMaxAge
public int getMaxAge()Returns the maximum age of the cookie in seconds.- Returns:
- the maximum age; -1 means session cookie
-
isSecure
public boolean isSecure()Returns whether the cookie is secure-only.- Returns:
- true if the cookie should only be sent over HTTPS
-
isHttpOnly
public boolean isHttpOnly()Returns whether the cookie is HTTP-only.- Returns:
- true if the cookie is inaccessible to client-side scripts
-
getSameSite
Returns the SameSite attribute value.- Returns:
- the SameSite value, or
nullif not set
-