【问题标题】:How to set success and failure handlers in OAuth2 WebFlux如何在 OAuth2 WebFlux 中设置成功和失败处理程序
【发布时间】:2020-01-16 20:37:52
【问题描述】:

在 Spring Web(非响应式)中,我们可以为 oauth2login 设置成功和失败处理程序,如下所示:

http.oauth2Login()
    .successHandler(oauth2AuthenticationSuccessHandler)
    .failureHandler(oauth2AuthenticationFailureHandler)

但在 WebFlux 中,我们没有这些方法。当我查看ServerHttpSecurity.configure 时,我看到处理程序是硬编码的:

protected void configure(ServerHttpSecurity http) {

    ...

    RedirectServerAuthenticationSuccessHandler redirectHandler = new RedirectServerAuthenticationSuccessHandler();

    authenticationFilter.setAuthenticationSuccessHandler(redirectHandler);
    authenticationFilter.setAuthenticationFailureHandler(new ServerAuthenticationFailureHandler() {
        @Override
        public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange,
                AuthenticationException exception) {
            return Mono.error(exception);
        }
    });

    ...
}

我们是否有计划在近期的 Spring 版本中使这些可配置?我应该为此创建一张票吗?而且,目前,有什么方法可以覆盖这些?

【问题讨论】:

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


    【解决方案1】:

    从 Spring 5.2 版开始,有一种方法可以设置身份验证成功和失败处理程序。 ServerHttpSecurity。在OAuth2LoginSpec 下。您需要更新您的依赖项。

    【讨论】:

      猜你喜欢
      • 2014-07-21
      • 1970-01-01
      • 2015-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-27
      • 2021-08-07
      • 1970-01-01
      相关资源
      最近更新 更多