Top Fields Constructors Methods
io.undertow.servlet.spec

public Class SessionCookieConfigImpl

extends Object
implements SessionCookieConfig, SessionConfig
Class Inheritance
All Implemented Interfaces
io.undertow.server.session.SessionConfig, jakarta.servlet.SessionCookieConfig
Imports
io.undertow.server.HttpServerExchange, io.undertow.server.session.SessionConfig, io.undertow.servlet.UndertowServletMessages, jakarta.servlet.SessionCookieConfig, java.util.Collections, .Map, .TreeMap

Author
Stuart Douglas

Field Summary

Modifier and TypeField and Description
private final Map<String, String>
private static final boolean
private static final int
private static final boolean
private final SessionCookieConfig
private SessionConfig
private final ServletContextImpl

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
clearSession(final HttpServerExchange
The exchange
exchange
,
final String
The session id
sessionId
)

Implements io.undertow.server.session.SessionConfig.clearSession.

Clears this session from the exchange, removing the attachment and making any changes to the response necessary, such as clearing cookies.

public String
findSessionId(final HttpServerExchange
The exchange
exchange
)

Implements io.undertow.server.session.SessionConfig.findSessionId.

Retrieves a session id of an existing session from an exchange.

public String
getAttribute(final String
Name of attribute to return, case insensitive
name
)

Implements jakarta.servlet.SessionCookieConfig.getAttribute.

Obtain the value for a given session cookie attribute.

public Map<String, String>
getAttributes()

Implements jakarta.servlet.SessionCookieConfig.getAttributes.

Obtain the Map (keys are case insensitive) of all attributes and values, including those set via the attribute specific setters, (excluding version) for this SessionCookieConfig.

public String
getComment()

Implements jakarta.servlet.SessionCookieConfig.getComment.

Deprecated

With the adoption of support for RFC 6265, this method should no longer be used.

public String
getDomain()

Implements jakarta.servlet.SessionCookieConfig.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.

public SessionConfig
public int
getMaxAge()

Implements jakarta.servlet.SessionCookieConfig.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.

public String
getName()

Implements jakarta.servlet.SessionCookieConfig.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.

public String
getPath()

Implements jakarta.servlet.SessionCookieConfig.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.

public boolean
isHttpOnly()

Implements jakarta.servlet.SessionCookieConfig.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.

public boolean
isSecure()

Implements jakarta.servlet.SessionCookieConfig.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.

public String
rewriteUrl(final String originalUrl, final String sessionid)

Implements io.undertow.server.session.SessionConfig.rewriteUrl.

public SessionConfig.SessionCookieSource
public void
setAttribute(final String
Name of attribute to set, case insensitive
name
,
final String
Value of attribute
value
)

Implements jakarta.servlet.SessionCookieConfig.setAttribute.

Sets the value for the given session cookie attribute.

public void
setComment(final String
ignore
comment
)

Implements jakarta.servlet.SessionCookieConfig.setComment.

Deprecated

With the adoption of support for RFC 6265, this method should no longer be used.

public void
setDomain(final String
the cookie domain to use
domain
)

Implements jakarta.servlet.SessionCookieConfig.setDomain.

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.

public void
setFallback(final SessionConfig fallback)

public void
setHttpOnly(final boolean
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 otherwise
httpOnly
)

Implements jakarta.servlet.SessionCookieConfig.setHttpOnly.

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.

public void
setMaxAge(final int
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.
maxAge
)

Implements jakarta.servlet.SessionCookieConfig.setMaxAge.

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.

public void
setName(final String
the cookie name to use
name
)

Implements jakarta.servlet.SessionCookieConfig.setName.

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.

public void
setPath(final String
the cookie path to use
path
)

Implements jakarta.servlet.SessionCookieConfig.setPath.

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.

public void
setSecure(final boolean
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 secure
secure
)

Implements jakarta.servlet.SessionCookieConfig.setSecure.

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.

public void
setSessionId(final HttpServerExchange
The exchange
exchange
,
final String
The session
sessionId
)

Implements io.undertow.server.session.SessionConfig.setSessionId.

Attaches the session to the exchange.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributesback to summary
private final Map<String, String> attributes
DEFAULT_HTTP_ONLYback to summary
private static final boolean DEFAULT_HTTP_ONLY
DEFAULT_MAX_AGEback to summary
private static final int DEFAULT_MAX_AGE
DEFAULT_SECUREback to summary
private static final boolean DEFAULT_SECURE
delegateback to summary
private final SessionCookieConfig delegate
fallbackback to summary
private SessionConfig fallback
servletContextback to summary
private final ServletContextImpl servletContext

Constructor Detail

SessionCookieConfigImplback to summary
public SessionCookieConfigImpl(final ServletContextImpl servletContext)

Method Detail

clearSessionback to summary
public void clearSession(final HttpServerExchange exchange, final String sessionId)

Implements io.undertow.server.session.SessionConfig.clearSession.

Doc from io.undertow.server.session.SessionConfig.clearSession.

Clears this session from the exchange, removing the attachment and making any changes to the response necessary, such as clearing cookies.

Parameters
exchange:HttpServerExchange

The exchange

sessionId:String

The session id

Annotations
@Override
findSessionIdback to summary
public String findSessionId(final HttpServerExchange exchange)

Implements io.undertow.server.session.SessionConfig.findSessionId.

Doc from io.undertow.server.session.SessionConfig.findSessionId.

Retrieves a session id of an existing session from an exchange.

Parameters
exchange:HttpServerExchange

The exchange

Returns:String

The session id, or null

Annotations
@Override
getAttributeback to summary
public String getAttribute(final String name)

Implements jakarta.servlet.SessionCookieConfig.getAttribute.

Doc from jakarta.servlet.SessionCookieConfig.getAttribute.

Obtain the value for a given session cookie attribute. Values returned from this method must be consistent with the values set and returned by the attribute specific getters and setters in this class.

Parameters
name:String

Name of attribute to return, case insensitive

Returns:String

Value of specified attribute

Annotations
@Override
getAttributesback to summary
public Map<String, String> getAttributes()

Implements jakarta.servlet.SessionCookieConfig.getAttributes.

Doc from jakarta.servlet.SessionCookieConfig.getAttributes.

Obtain the Map (keys are case insensitive) of all attributes and values, including those set via the attribute specific setters, (excluding version) for this SessionCookieConfig.

Returns:Map<String, String>

A read-only Map of attributes to values, excluding version.

Annotations
@Override
getCommentback to summary
public String getComment()

Implements jakarta.servlet.SessionCookieConfig.getComment.

Doc from jakarta.servlet.SessionCookieConfig.getComment.

Deprecated

With the adoption of support for RFC 6265, this method should no longer be used.

Returns:String

Always null

Annotations
@Deprecated
getDomainback to summary
public String getDomain()

Implements jakarta.servlet.SessionCookieConfig.getDomain.

Doc from jakarta.servlet.SessionCookieConfig.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.

Returns:String

the cookie domain set via setDomain, or null if setDomain was never called

getFallbackback to summary
public SessionConfig getFallback()
getMaxAgeback to summary
public int getMaxAge()

Implements jakarta.servlet.SessionCookieConfig.getMaxAge.

Doc from jakarta.servlet.SessionCookieConfig.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.

By default, -1 is returned.

Returns:int

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, or -1 (the default)

getNameback to summary
public String getName()

Implements jakarta.servlet.SessionCookieConfig.getName.

Doc from jakarta.servlet.SessionCookieConfig.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.

By default, JSESSIONID will be used as the cookie name.

Returns:String

the cookie name set via setName, or null if setName was never called

getPathback to summary
public String getPath()

Implements jakarta.servlet.SessionCookieConfig.getPath.

Doc from jakarta.servlet.SessionCookieConfig.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.

By default, the context path of the ServletContext from which this SessionCookieConfig was acquired will be used.

Returns:String

the cookie path set via setPath, or null if setPath was never called

isHttpOnlyback to summary
public boolean isHttpOnly()

Implements jakarta.servlet.SessionCookieConfig.isHttpOnly.

Doc from jakarta.servlet.SessionCookieConfig.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.

Returns:boolean

true 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, false otherwise

isSecureback to summary
public boolean isSecure()

Implements jakarta.servlet.SessionCookieConfig.isSecure.

Doc from jakarta.servlet.SessionCookieConfig.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.

Returns:boolean

true 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, and false if they will be marked as secure only if the request that initiated the corresponding session was also secure

rewriteUrlback to summary
public String rewriteUrl(final String originalUrl, final String sessionid)

Implements io.undertow.server.session.SessionConfig.rewriteUrl.

Annotations
@Override
sessionCookieSourceback to summary
public SessionConfig.SessionCookieSource sessionCookieSource(HttpServerExchange exchange)

Implements io.undertow.server.session.SessionConfig.sessionCookieSource.

Annotations
@Override
setAttributeback to summary
public void setAttribute(final String name, final String value)

Implements jakarta.servlet.SessionCookieConfig.setAttribute.

Doc from jakarta.servlet.SessionCookieConfig.setAttribute.

Sets the value for the given session cookie attribute. When a value is set via this method, the value returned by the attribute specific getter (if any) must be consistent with the value set via this method.

Parameters
name:String

Name of attribute to set, case insensitive

value:String

Value of attribute

Annotations
@Override
setCommentback to summary
public void setComment(final String comment)

Implements jakarta.servlet.SessionCookieConfig.setComment.

Doc from jakarta.servlet.SessionCookieConfig.setComment.

Deprecated

With the adoption of support for RFC 6265, this method should no longer be used.

If called, this method has no effect.

Parameters
comment:String

ignore

Annotations
@Deprecated
setDomainback to summary
public void setDomain(final String domain)

Implements jakarta.servlet.SessionCookieConfig.setDomain.

Doc from jakarta.servlet.SessionCookieConfig.setDomain.

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.

Parameters
domain:String

the cookie domain to use

setFallbackback to summary
public void setFallback(final SessionConfig fallback)
setHttpOnlyback to summary
public void setHttpOnly(final boolean httpOnly)

Implements jakarta.servlet.SessionCookieConfig.setHttpOnly.

Doc from jakarta.servlet.SessionCookieConfig.setHttpOnly.

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.

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.

Parameters
httpOnly:boolean

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 otherwise

setMaxAgeback to summary
public void setMaxAge(final int maxAge)

Implements jakarta.servlet.SessionCookieConfig.setMaxAge.

Doc from jakarta.servlet.SessionCookieConfig.setMaxAge.

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.

Parameters
maxAge:int

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.

setNameback to summary
public void setName(final String name)

Implements jakarta.servlet.SessionCookieConfig.setName.

Doc from jakarta.servlet.SessionCookieConfig.setName.

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.

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.

Parameters
name:String

the cookie name to use

setPathback to summary
public void setPath(final String path)

Implements jakarta.servlet.SessionCookieConfig.setPath.

Doc from jakarta.servlet.SessionCookieConfig.setPath.

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.

Parameters
path:String

the cookie path to use

setSecureback to summary
public void setSecure(final boolean secure)

Implements jakarta.servlet.SessionCookieConfig.setSecure.

Doc from jakarta.servlet.SessionCookieConfig.setSecure.

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.

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.

Parameters
secure:boolean

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 secure

setSessionIdback to summary
public void setSessionId(final HttpServerExchange exchange, final String sessionId)

Implements io.undertow.server.session.SessionConfig.setSessionId.

Doc from io.undertow.server.session.SessionConfig.setSessionId.

Attaches the session to the exchange. The method should attach the exchange under an attachment key, and should also modify the exchange to allow the session to be re-attached on the next request.

Generally this will involve setting a cookie

Once a session has been attached it must be possible to retrieve it via findSessionId(io.undertow.server.HttpServerExchange)

Parameters
exchange:HttpServerExchange

The exchange

sessionId:String

The session

Annotations
@Override