spring-boot - WebSocket 握手期间出错:“Sec-WebSocket-Accept”标头值不正确
问题描述
我有一个 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
有没有办法解决这个问题?我担心在负载均衡器后面运行它会导致这个错误一直发生。
这是基于messaging-stomp-websocket示例+ spring-security websocket-authentication
解决方案
似乎 spring-security-webRequestCacheAwareFilter
提取了一个缓存的请求,导致实际的Sec-WebSocket-Key标头值被无效的值替换。
事件的顺序是,每次客户端尝试重新连接时,客户端发出两个 websocket 请求,第一个被WWW-Authenticate: Negotiate header 拒绝,第二个包含Authorization header 有不同的Sec-WebSocket-Key价值。
我能够通过完全禁用缓存来解决这个问题,例如在WebSecurityConfigurerAdapter
@Override
protected void configure(final HttpSecurity http) throws Exception {
http.requestCache().requestCache(new NullRequestCache())
}
推荐阅读
- mysql - mysql.server start 不会启动 mysql 服务器
- r - Shiny R:仪表板标题中的语言按钮
- python - 暂停 PyTest 并等待用户输入
- javascript - 更新所选项目时如何防止jquery-ui selectmenu变慢
- spring-security - Spring Cloud Config 服务器认证
- c# - Devexpress 主详细信息
- docker - Jenkins 的 K8s 插件:始终在一个 pod 内运行两个单独的容器
- sparql - DBpedia 检索的 Sparql 查询问题
- ruby-on-rails - Rails 应用程序中的自定义迁移失败
- android - Eddystone,getBeaconAdvertisementData(beacon) 是什么意思?