public final class CookieManager extends AbstractInitializableComponent
This bean centralizes settings related to cookie creation and access, and is parametrized by name so that multiple cookies may be managed with common properties.
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
cookieDomain
Domain of cookie.
|
private java.lang.String |
cookiePath
Path of cookie.
|
private boolean |
httpOnly
Is cookie marked HttpOnly?
|
private javax.servlet.http.HttpServletRequest |
httpRequest
Servlet request to read from.
|
private javax.servlet.http.HttpServletResponse |
httpResponse
Servlet response to write to.
|
private int |
maxAge
Maximum age in seconds, or -1 for session.
|
private boolean |
secure
Is cookie secure?
|
| Constructor and Description |
|---|
CookieManager()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCookie(java.lang.String name,
java.lang.String value)
Add a cookie with the specified name and value.
|
private java.lang.String |
contextPathToCookiePath()
Turn the servlet context path into an appropriate cookie path.
|
protected void |
doInitialize()
Performs the initialization of the component.
|
void |
setCookieDomain(java.lang.String domain)
Set the cookie domain to use for session tracking.
|
void |
setCookiePath(java.lang.String path)
Set the cookie path to use for session tracking.
|
void |
setHttpOnly(boolean flag)
Set the HttpOnly flag.
|
void |
setHttpServletRequest(javax.servlet.http.HttpServletRequest request)
Set the servlet request to read from.
|
void |
setHttpServletResponse(javax.servlet.http.HttpServletResponse response)
Set the servlet response to write to.
|
void |
setMaxAge(int age)
Maximum age in seconds, or -1 for per-session.
|
void |
setSecure(boolean flag)
Set the SSL-only flag.
|
void |
unsetCookie(java.lang.String name)
Unsets a cookie with the specified name.
|
destroy, doDestroy, initialize, isDestroyed, isInitialized@Nullable private java.lang.String cookiePath
@Nullable private java.lang.String cookieDomain
@NonnullAfterInit private javax.servlet.http.HttpServletRequest httpRequest
@NonnullAfterInit private javax.servlet.http.HttpServletResponse httpResponse
private boolean secure
private boolean httpOnly
private int maxAge
public void setCookiePath(@Nullable
java.lang.String path)
Defaults to the servlet context path.
path - cookie path to use, or null for the defaultpublic void setCookieDomain(@Nullable
java.lang.String domain)
domain - the cookie domain to use, or null for the defaultpublic void setHttpServletRequest(@Nonnull
javax.servlet.http.HttpServletRequest request)
request - servlet requestpublic void setHttpServletResponse(@Nonnull
javax.servlet.http.HttpServletResponse response)
response - servlet responsepublic void setSecure(boolean flag)
flag - flag to setpublic void setHttpOnly(boolean flag)
flag - flag to setpublic void setMaxAge(int age)
age - max age to setprotected void doInitialize()
throws ComponentInitializationException
doInitialize in class AbstractInitializableComponentComponentInitializationException - thrown if there is a problem initializing the component@Nullable public void addCookie(@Nonnull @NotEmpty java.lang.String name, @Nonnull @NotEmpty java.lang.String value)
name - name of cookievalue - value of cookie@Nullable public void unsetCookie(@Nonnull @NotEmpty java.lang.String name)
name - name of cookie@Nonnull @NotEmpty private java.lang.String contextPathToCookiePath()