spring-framework / org.springframework.web.socket.server.support / HttpSessionHandshakeInterceptor

HttpSessionHandshakeInterceptor

open class HttpSessionHandshakeInterceptor : HandshakeInterceptor

An interceptor to copy information from the HTTP session to the "handshake attributes" map to made available viaWebSocketSession#getAttributes().

Copies a subset or all HTTP session attributes and/or the HTTP session id under the key #HTTP_SESSION_ID_ATTR_NAME.

Author
Rossen Stoyanchev

Since
4.0

Constructors

<init>

HttpSessionHandshakeInterceptor()

Default constructor for copying all HTTP session attributes and the HTTP session id.

HttpSessionHandshakeInterceptor(attributeNames: MutableCollection<String>)

Constructor for copying specific HTTP session attributes and the HTTP session id.

Properties

HTTP_SESSION_ID_ATTR_NAME

static val HTTP_SESSION_ID_ATTR_NAME: String

The name of the attribute under which the HTTP session id is exposed when copyHttpSessionId is "true".

Functions

afterHandshake

open fun afterHandshake(request: ServerHttpRequest, response: ServerHttpResponse, wsHandler: WebSocketHandler, ex: Exception): Unit

beforeHandshake

open fun beforeHandshake(request: ServerHttpRequest, response: ServerHttpResponse, wsHandler: WebSocketHandler, attributes: MutableMap<String, Any>): Boolean

getAttributeNames

open fun getAttributeNames(): MutableCollection<String>

Return the configured attribute names to copy (read-only).

isCopyAllAttributes

open fun isCopyAllAttributes(): Boolean

Whether to copy all HTTP session attributes.

isCopyHttpSessionId

open fun isCopyHttpSessionId(): Boolean

Whether to copy the HTTP session id to the handshake attributes.

isCreateSession

open fun isCreateSession(): Boolean

Whether the HTTP session is allowed to be created.

setCopyAllAttributes

open fun setCopyAllAttributes(copyAllAttributes: Boolean): Unit

Whether to copy all attributes from the HTTP session. If set to "true", any explicitly configured attribute names are ignored.

By default this is set to either "true" or "false" depending on which constructor was used (default or with attribute names respectively).

setCopyHttpSessionId

open fun setCopyHttpSessionId(copyHttpSessionId: Boolean): Unit

Whether the HTTP session id should be copied to the handshake attributes under the key #HTTP_SESSION_ID_ATTR_NAME.

By default this is "true".

setCreateSession

open fun setCreateSession(createSession: Boolean): Unit

Whether to allow the HTTP session to be created while accessing it.

By default set to false.