使用 OIDC 时未在 websocket OnOpen 调用中设置 Quarkus SecurityIdentity

问题描述

我有一个使用 quarkus-oidc 进行用户身份验证的 Quarkus (1.6.1.Final) 应用程序。我的服务器有一个 websocket 端点:

@ApplicationScoped
@ServerEndpoint(value="/websocket")
public class WebsocketEndpoint {
  @Inject
  SecurityIdentity identity;

  @Onopen
  public void onopen(Session session) {
    // at this point identity is always Anonymous,even if I use a valid auth header that works correctly on a normal REST endpoint.
  }
}

我希望能够在此端点上进行一些用户身份验证,最好是通过类上的 @RolesAllowed 注释。通过连接调试器,我可以单步执行 OidcAuthenticationMechanism 并验证是否正在构造 SecurityIdentity 对象并正确反映 JWT 的内容 - 但是,当我到达 {{1} }} 回调,它不再设置。 (同样,在我的端点上使用 Onopen 的任何尝试都会失败,因为 @RolesAllowedSecurityIdentity 调用中的匿名用户。)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)