类 OriginHandshakeInterceptor
- java.lang.Object
- org.springframework.web.socket.server.support.OriginHandshakeInterceptor
- 所有已实现的接口:
HandshakeInterceptor
public class OriginHandshakeInterceptor extends Object implements HandshakeInterceptor
An interceptor to check requestOrigin
header value against a collection of allowed origins.- 从以下版本开始:
- 4.1.2
- 作者:
- Sebastien Deleuze
构造器概要
构造器 构造器 说明 OriginHandshakeInterceptor()
Default constructor with only same origin requests allowed.OriginHandshakeInterceptor(Collection<String> allowedOrigins)
Constructor using the specified allowed origin values.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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()
Return the allowedOrigin
header values.void
setAllowedOrigins(Collection<String> allowedOrigins)
Configure allowedOrigin
header values.
构造器详细资料
OriginHandshakeInterceptor
public OriginHandshakeInterceptor()
Default constructor with only same origin requests allowed.
OriginHandshakeInterceptor
public OriginHandshakeInterceptor(Collection<String> allowedOrigins)
Constructor using the specified allowed origin values.
方法详细资料
setAllowedOrigins
public void setAllowedOrigins(Collection<String> allowedOrigins)
Configure allowedOrigin
header values. This check is mostly designed for browsers. There is nothing preventing other types of client to modify theOrigin
header value.Each provided allowed origin must have a scheme, and optionally a port (e.g. "https://example.org", "https://example.org:9090"). An allowed origin string may also be "*" in which case all origins are allowed.
getAllowedOrigins
public Collection<String> getAllowedOrigins()
Return the allowedOrigin
header values.- 从以下版本开始:
- 4.1.5
- 另请参阅:
setAllowedOrigins(java.util.Collection<java.lang.String>)
beforeHandshake
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String,Object> attributes) throws Exception
从接口复制的说明:HandshakeInterceptor
Invoked before the handshake is processed.- 指定者:
beforeHandshake
在接口中HandshakeInterceptor
- 参数:
request
- the current requestresponse
- the current responsewsHandler
- the target WebSocket handlerattributes
- the attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.- 返回:
- whether to proceed with the handshake (
true
) or abort (false
) - 抛出:
Exception
afterHandshake
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, @Nullable Exception exception)
从接口复制的说明:HandshakeInterceptor
Invoked after the handshake is done. The response status and headers indicate the results of the handshake, i.e. whether it was successful or not.- 指定者:
afterHandshake
在接口中HandshakeInterceptor
- 参数:
request
- the current requestresponse
- the current responsewsHandler
- the target WebSocket handlerexception
- an exception raised during the handshake, ornull
if none