我们有一个 Spring-MVC 应用程序,其 Websockets 部署在 Jetty 服务器上。我们还为 jetty 配置了如下所示的 HashLoginService。当应用程序启动时,我们可以在 FF、Chrome、Opera、IE 上使用完整的 websockets 功能访问它,但在 Safari 上则不行。我们唯一返回的是 401。禁用 HashLoginService 后,websockets 工作正常。 Jetty 或其他地方是否需要进行一些配置,以便 websocket 在 Safari 中通过身份验证工作。谢谢。
Safari version : 11.0.3(desktop version)
Jetty - 9.4
jetty.xml:
<Arg>
<New class="org.eclipse.jetty.security.HashLoginService">
<Set name="name">Default Realm</Set>
<Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
</New>
</Arg>
</Call>
项目中的 web.xml:
<security-constraint>
<web-resource-collection>
<web-resource-name>username</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user-role</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>username</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user-role</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>user-role</role-name>
</security-role>
知道我们能做什么吗?谢谢。
最佳答案
Safari 和 WebSocket 显然不支持标准 HTTP 身份验证。
参见:https://bugs.webkit.org/show_bug.cgi?id=80362
您可以在不同的 stackoverflow 答案中找到一些解决方法。
关于authentication - Safari , jetty : Websockets not working as authentication header is not sent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49321148/