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 String |
cookieDomain
Domain of cookie.
|
private 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(String name,
String value)
Add a cookie with the specified name and value.
|
private String |
contextPathToCookiePath()
Turn the servlet context path into an appropriate cookie path.
|
protected void |
doInitialize()
Performs the initialization of the component.
|
void |
setCookieDomain(String domain)
Set the cookie domain to use for session tracking.
|
void |
setCookiePath(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(String name)
Unsets a cookie with the specified name.
|
destroy, doDestroy, initialize, isDestroyed, isInitialized
@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 String path)
Defaults to the servlet context path.
path
- cookie path to use, or null for the defaultpublic void setCookieDomain(@Nullable 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 AbstractInitializableComponent
ComponentInitializationException
- thrown if there is a problem initializing the component@Nullable public void addCookie(@Nonnull @NotEmpty String name, @Nonnull @NotEmpty String value)
name
- name of cookievalue
- value of cookie@Nullable public void unsetCookie(@Nonnull @NotEmpty String name)
name
- name of cookieCopyright © 1999–2018. All rights reserved.