public class SessionCookieConfigImpl extends Object implements SessionCookieConfig, SessionConfig
SessionConfig.SessionCookieSource
ATTACHMENT_KEY
Constructor and Description |
---|
SessionCookieConfigImpl(ServletContextImpl servletContext) |
Modifier and Type | Method and Description |
---|---|
void |
clearSession(HttpServerExchange exchange,
String sessionId)
Clears this session from the exchange, removing the attachment and making any changes to the response necessary,
such as clearing cookies.
|
String |
findSessionId(HttpServerExchange exchange)
Retrieves a session id of an existing session from an exchange.
|
String |
getComment()
Gets the comment that will be assigned to any session tracking cookies created on behalf of the application
represented by the ServletContext from which this SessionCookieConfig was acquired.
|
String |
getDomain()
Gets the domain name that will be assigned to any session tracking cookies created on behalf of the application
represented by the ServletContext from which this SessionCookieConfig was acquired.
|
SessionConfig |
getFallback() |
int |
getMaxAge()
Gets the lifetime (in seconds) of the session tracking cookies created on behalf of the application represented
by the ServletContext from which this SessionCookieConfig was acquired.
|
String |
getName()
Gets the name that will be assigned to any session tracking cookies created on behalf of the application
represented by the ServletContext from which this SessionCookieConfig was acquired.
|
String |
getPath()
Gets the path that will be assigned to any session tracking cookies created on behalf of the application
represented by the ServletContext from which this SessionCookieConfig was acquired.
|
boolean |
isHttpOnly()
Checks if the session tracking cookies created on behalf of the application represented by the
ServletContext from which this SessionCookieConfig was acquired will be marked as
HttpOnly.
|
boolean |
isSecure()
Checks if the session tracking cookies created on behalf of the application represented by the
ServletContext from which this SessionCookieConfig was acquired will be marked as secure
even if the request that initiated the corresponding session is using plain HTTP instead of HTTPS.
|
String |
rewriteUrl(String originalUrl,
String sessionid) |
SessionConfig.SessionCookieSource |
sessionCookieSource(HttpServerExchange exchange) |
void |
setComment(String comment)
Sets the comment that will be assigned to any session tracking cookies created on behalf of the application
represented by the ServletContext from which this SessionCookieConfig was acquired.
|
void |
setDomain(String domain)
Sets the domain name that will be assigned to any session tracking cookies created on behalf of the application
represented by the ServletContext from which this SessionCookieConfig was acquired.
|
void |
setFallback(SessionConfig fallback) |
void |
setHttpOnly(boolean httpOnly)
Marks or unmarks the session tracking cookies created on behalf of the application represented by the
ServletContext from which this SessionCookieConfig was acquired as HttpOnly.
|
void |
setMaxAge(int maxAge)
Sets the lifetime (in seconds) for the session tracking cookies created on behalf of the application represented
by the ServletContext from which this SessionCookieConfig was acquired.
|
void |
setName(String name)
Sets the name that will be assigned to any session tracking cookies created on behalf of the application
represented by the ServletContext from which this SessionCookieConfig was acquired.
|
void |
setPath(String path)
Sets the path that will be assigned to any session tracking cookies created on behalf of the application
represented by the ServletContext from which this SessionCookieConfig was acquired.
|
void |
setSecure(boolean secure)
Marks or unmarks the session tracking cookies created on behalf of the application represented by the
ServletContext from which this SessionCookieConfig was acquired as secure.
|
void |
setSessionId(HttpServerExchange exchange,
String sessionId)
Attaches the session to the exchange.
|
public SessionCookieConfigImpl(ServletContextImpl servletContext)
public String rewriteUrl(String originalUrl, String sessionid)
rewriteUrl
in interface SessionConfig
public void setSessionId(HttpServerExchange exchange, String sessionId)
SessionConfig
Generally this will involve setting a cookie
Once a session has been attached it must be possible to retrieve it via
SessionConfig.findSessionId(io.undertow.server.HttpServerExchange)
setSessionId
in interface SessionConfig
exchange
- The exchangesessionId
- The sessionpublic void clearSession(HttpServerExchange exchange, String sessionId)
SessionConfig
clearSession
in interface SessionConfig
exchange
- The exchangesessionId
- The session idpublic String findSessionId(HttpServerExchange exchange)
SessionConfig
findSessionId
in interface SessionConfig
exchange
- The exchangepublic SessionConfig.SessionCookieSource sessionCookieSource(HttpServerExchange exchange)
sessionCookieSource
in interface SessionConfig
public String getName()
SessionCookieConfig
By default, JSESSIONID will be used as the cookie name.
getName
in interface SessionCookieConfig
SessionCookieConfig.setName(java.lang.String)
, or null if SessionCookieConfig.setName(java.lang.String)
was never calledCookie.getName()
public void setName(String name)
SessionCookieConfig
NOTE: Changing the name of session tracking cookies may break other tiers (for example, a load balancing frontend) that assume the cookie name to be equal to the default JSESSIONID, and therefore should only be done cautiously.
setName
in interface SessionCookieConfig
name
- the cookie name to usepublic String getDomain()
SessionCookieConfig
getDomain
in interface SessionCookieConfig
SessionCookieConfig.setDomain(java.lang.String)
, or null if SessionCookieConfig.setDomain(java.lang.String)
was never calledCookie.getDomain()
public void setDomain(String domain)
SessionCookieConfig
setDomain
in interface SessionCookieConfig
domain
- the cookie domain to useCookie.setDomain(String)
public String getPath()
SessionCookieConfig
By default, the context path of the ServletContext from which this SessionCookieConfig was acquired will be used.
getPath
in interface SessionCookieConfig
SessionCookieConfig.setPath(java.lang.String)
, or null if SessionCookieConfig.setPath(java.lang.String)
was never calledCookie.getPath()
public void setPath(String path)
SessionCookieConfig
setPath
in interface SessionCookieConfig
path
- the cookie path to useCookie.setPath(String)
public String getComment()
SessionCookieConfig
getComment
in interface SessionCookieConfig
SessionCookieConfig.setComment(java.lang.String)
, or null if SessionCookieConfig.setComment(java.lang.String)
was never calledCookie.getComment()
public void setComment(String comment)
SessionCookieConfig
As a side effect of this call, the session tracking cookies will be marked with a Version
attribute
equal to 1
.
setComment
in interface SessionCookieConfig
comment
- the cookie comment to useCookie.setComment(String)
,
Cookie.getVersion()
public boolean isHttpOnly()
SessionCookieConfig
isHttpOnly
in interface SessionCookieConfig
Cookie.isHttpOnly()
public void setHttpOnly(boolean httpOnly)
SessionCookieConfig
A cookie is marked as HttpOnly by adding the HttpOnly attribute to it. HttpOnly cookies are not supposed to be exposed to client-side scripting code, and may therefore help mitigate certain kinds of cross-site scripting attacks.
setHttpOnly
in interface SessionCookieConfig
httpOnly
- true if the session tracking cookies created on behalf of the application represented by the
ServletContext from which this SessionCookieConfig was acquired shall be marked
as HttpOnly, false otherwiseCookie.setHttpOnly(boolean)
public boolean isSecure()
SessionCookieConfig
isSecure
in interface SessionCookieConfig
Cookie.getSecure()
,
ServletRequest.isSecure()
public void setSecure(boolean secure)
SessionCookieConfig
One use case for marking a session tracking cookie as secure, even though the request that initiated the session came over HTTP, is to support a topology where the web container is front-ended by an SSL offloading load balancer. In this case, the traffic between the client and the load balancer will be over HTTPS, whereas the traffic between the load balancer and the web container will be over HTTP.
setSecure
in interface SessionCookieConfig
secure
- true if the session tracking cookies created on behalf of the application represented by the
ServletContext from which this SessionCookieConfig was acquired shall be marked
as secure even if the request that initiated the corresponding session is using plain HTTP
instead of HTTPS, and false if they shall be marked as secure only if the request that
initiated the corresponding session was also secureCookie.setSecure(boolean)
,
ServletRequest.isSecure()
public int getMaxAge()
SessionCookieConfig
By default, -1 is returned.
getMaxAge
in interface SessionCookieConfig
Cookie.getMaxAge()
public void setMaxAge(int maxAge)
SessionCookieConfig
setMaxAge
in interface SessionCookieConfig
maxAge
- the lifetime (in seconds) of the session tracking cookies created on behalf of the application
represented by the ServletContext from which this SessionCookieConfig was
acquired.Cookie.setMaxAge(int)
public SessionConfig getFallback()
public void setFallback(SessionConfig fallback)
Copyright © 2021 JBoss by Red Hat. All rights reserved.