使用 WebFlux 和 OAuth2 (oauth2Login) 的 Spring Security 自定义登录页面

And*_*eas 5 java spring-security spring-security-oauth2 spring-webflux

Spring Security 5.1.4启用WebFlux应用程序并启用OAuth2 的情况下,我没有找到任何方法来覆盖为/login. 我过去只是简单地创建一个控制器,/login但是控制器没有被击中。

到目前为止我发现的唯一“解决方案”是设置httpSecurity.exceptionHandling().authenticationEntryPoint(...)

令我惊讶的是,登录控制器开始工作,因为这会阻止LoginPageSpec生成LoginPageGeneratingWebFilter.

在这样的设置中是否有任何旨在用于覆盖登录页面的工具?

var httpSecurity =
    http.authorizeExchange()
        .anyExchange()
        .authenticated()
        .and()
        .oauth2Login()
        .authenticationConverter(tokenConverter)
        .and()
        .logout()
        .logoutHandler(new KeycloakLogoutHandler(serverOAuth2AuthorizedClientRepository()))
        .logoutSuccessHandler(logoutSuccessHandler)
        .logoutUrl("/sso/logout")
        .and()
        .csrf()
        .disable()
        .authenticationEntryPoint(new RedirectServerAuthenticationEntryPoint("/login"))
        .and()
        .build();
Run Code Online (Sandbox Code Playgroud)