WebSocket握手期间错误:错误的“ Sec-WebSocket-Accept”头值

时间:2018-09-21 13:01:40

标签: spring-boot spring-security stompjs

我有一个spring-boot websocket连接,该连接位于spring-security-kerberos后面以实现SSO。这可以按预期工作,但是如果我重新启动服务器,则会看到客户端无法重新连接,并显示错误Error during WebSocket handshake: Incorrect 'Sec-WebSocket-Accept' header value

我正在使用@stomp/stompjs 4.0.8并设置stompClient.reconnect_delay = 5000

有什么办法解决这个问题?我担心在负载平衡器后面运行它会导致始终出现此错误。

这基于the messaging-stomp-websocket example + spring-security websocket-authentication

1 个答案:

答案 0 :(得分:1)

似乎spring-security-web RequestCacheAwareFilter提取了一个缓存的请求,该请求导致实际的 Sec-WebSocket-Key 标头值替换为无效的请求值。

事件的顺序是,客户端每次尝试重新连接时,客户端都会发出两个websocket请求,第一个请求被 WWW-Authenticate:Negotiate 标头拒绝,第二个包含一个 Authorization 标头具有不同的 Sec-WebSocket-Key 值。

我能够通过完全禁用缓存来解决此问题,例如在WebSecurityConfigurerAdapter

@Override
protected void configure(final HttpSecurity http) throws Exception {
    http.requestCache().requestCache(new NullRequestCache())
}