如何在SpringBoot WebFlux中使用GET请求注销

好奇的

如何配置securityWebFilterChain(ServerHttpSecurity http)以便我的应用程序注销GET /logout

我有SpringBoot 2 Spring 5WebFlux

我试过了:

  http
    .logout()
      .requiresLogout(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/logout"))
      .logoutSuccessHandler(logoutSuccessHandler("/after-life"))

问题是,a LogoutPageGeneratingWebFilterLogoutWebFilter发出的早坐SecurityWebFilterChain在那里有一个硬编码.pathMatchers(HttpMethod.GET, "/logout")-这导致我的应用程序始终在GET请求上发出html页面。

我找不到抑制自动注销页面生成的方法:(

巴拉斯:

文档中所述

默认是Spring Security将在“ / login”处生成一个登录页面,并在“ / logout”处生成一个注销页面。如果是自定义的:不再提供默认的“登录和注销”页面。应用程序必须在提供的URL上呈现登录页面。应用程序必须在提供的URL上呈现认证错误页面+“?error”。 POST到提供的URL

自定义配置以具有默认登录名而没有默认注销。

    @Bean
    public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity httpSecurity){

        LoginPageGeneratingWebFilter loginpage= new LoginPageGeneratingWebFilter();
        loginpage.setFormLoginEnabled(true);
        return httpSecurity
                .addFilterAt(loginpage, SecurityWebFiltersOrder.LOGIN_PAGE_GENERATING)
                .authorizeExchange()
                    .pathMatchers("/home").authenticated()
                        .and().formLogin()                      
                            .loginPage("/login")                         
                        .and()
                        .logout()
                        .logoutUrl("/logout").requiresLogout(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/logout"))
                        .and()

                .build();

    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在springboot中使用path和request参数创建/调用rest控制器

如何在异步中使用请求?

如何在SpringBoot中使用Lambok依赖关系?

如何在Spring Webflux中使用@RequestBody并避免IllegalStateException?

在将响应返回给调用方时,如何注销对Spring WebFlux WebClient请求的失败响应的主体?

如何在SpringBoot中使用单个@postmapping填充多个表

如何在SpringBoot中使用SimpleUrlHandlerMapping

如何在Springboot中禁止`DELETE` http请求?

如何在Spring WebFlux中使用WebSession持久化数据?

如何在Springboot Restcontroller中使用PUT方法?

如何在Laravel中使用补丁请求?

如何注销API?在Laravel中使用Passport

如何在Alamofire中使用PUT请求

如何在Spring WebFlux中使用Jaeger?

如何在nifi中使用invoke HTTP执行GET请求?

如何在Swift中使用Firebase处理脱机注销?

如何在SpringBoot应用程序中使用hikari配置自动重新连接?

如何在POST请求中正确连接SpringBoot JPA实体?

如何在请求正文中使用JSON进行GET请求

如何在Android中使用HttpGet请求?

如何在Angular的GET请求中使用URL参数?

如何在无gnome的环境中使用命令注销?

如何在JMeter中使用curl请求?

如何在SpringBoot中使用ebean-spring?

如何在改造请求中使用@path

如何在 springboot 或 JPA 中使用索引

如何在请求中使用代理

如何在 Spring RestController 中使用 body 测试 GET 请求?

如何在 Java Springboot JPA 中使用 PostgreSQL 存储列表?