public class OriginHandshakeInterceptor extends Object implements HandshakeInterceptor
Origin
header value against a collection of
allowed origins.Constructor and Description |
---|
OriginHandshakeInterceptor()
Default constructor with only same origin requests allowed.
|
OriginHandshakeInterceptor(Collection<String> allowedOrigins)
Constructor using the specified allowed origin values.
|
Modifier and Type | Method and Description |
---|---|
void |
afterHandshake(ServerHttpRequest request,
ServerHttpResponse response,
WebSocketHandler wsHandler,
Exception exception)
Invoked after the handshake is done.
|
boolean |
beforeHandshake(ServerHttpRequest request,
ServerHttpResponse response,
WebSocketHandler wsHandler,
Map<String,Object> attributes)
Invoked before the handshake is processed.
|
Collection<String> |
getAllowedOrigins() |
void |
setAllowedOrigins(Collection<String> allowedOrigins)
Configure allowed
Origin header values. |
protected Log logger
public OriginHandshakeInterceptor()
public OriginHandshakeInterceptor(Collection<String> allowedOrigins)
setAllowedOrigins(Collection)
public void setAllowedOrigins(Collection<String> allowedOrigins)
Origin
header values. This check is mostly designed for
browser clients. There is nothing preventing other types of client to modify the
Origin
header value.
Each provided allowed origin must start by "http://", "https://" or be "*" (means that all origins are allowed).
public Collection<String> getAllowedOrigins()
setAllowedOrigins(Collection)
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String,Object> attributes) throws Exception
HandshakeInterceptor
beforeHandshake
in interface HandshakeInterceptor
request
- the current requestresponse
- the current responsewsHandler
- the target WebSocket handlerattributes
- attributes from the HTTP handshake to associate with the WebSocket
session; the provided attributes are copied, the original map is not used.true
) or abort (false
)Exception
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception)
HandshakeInterceptor
afterHandshake
in interface HandshakeInterceptor
request
- the current requestresponse
- the current responsewsHandler
- the target WebSocket handlerexception
- an exception raised during the handshake, or null
if none