【问题标题】:Is it possilble to add a response body using a customized ServerAuthenticationEntryPoint?是否可以使用自定义的 ServerAuthenticationEntryPoint 添加响应正文?
【发布时间】:2019-11-15 11:45:30
【问题描述】:

我已经看到,在 5.2.0.M1 版本中,当在反应式堆栈 (Webflux) 上使用 Spring Security 的 OAuth2 资源服务器时,无法自定义 ServerAuthenticationEntryPoint。

(另见https://github.com/spring-projects/spring-security/issues/6052

但是,当我现在尝试编写自己的 ServerAuthenticationEntryPoint 时,我在问自己如何向 http 响应添加正文? begin(...) 方法返回一个 Mono 并且我还没有找到在某处指定正文的方法。

谁能给我一个提示(如果可能的话)?

【问题讨论】:

    标签: spring-security spring-security-oauth2 spring-webflux


    【解决方案1】:

    与此同时,我找到了解决此问题的方法。当像这样在 WebSecurityConfiguration 类中的 ServerHttpSecurity 配置中添加一个 lambda 时

    http
      . ...
      .oauth2ResourceServer()
      .authenticationEntryPoint((exchange, exception) -> Mono.error(exception));
    

    我可以在 AbstractErrorWebExceptionHandler 的自定义实现中处理错误,无论如何我都会处理所有非 Spring 安全相关的异常。这行得通。我不得不从 BearerTokenServerAuthenticationEntryPoint 中复制一些逻辑,以在响应中获得正确的 WWW-Authenticate 标头,但现在它可以在自定义正文中正常工作,以防 Spring Security 出现任何异常。 p>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      • 2012-05-05
      • 2019-10-22
      • 2019-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多