Как мне настроить securityWebFilterChain(ServerHttpSecurity http)
, чтобы мое приложение вышло из системы GET /logout
?
У меня есть SpringBoot 2
Spring 5
и WebFlux
Я старался:
http
.logout()
.requiresLogout(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/logout"))
.logoutSuccessHandler(logoutSuccessHandler("/after-life"))
Проблема в том, что LogoutPageGeneratingWebFilter
находится перед LogoutWebFilter
в испускаемом SecurityWebFilterChain
. В этом есть жестко запрограммированный .pathMatchers(HttpMethod.GET, "/logout")
, который заставляет мое приложение всегда выдавать html-страницу по запросу GET.
Я не нашел способа подавить автоматическую генерацию страницы выхода :(
Как указано в документация,
The default is that Spring Security will generate a log in page at "/login" and a log out page at "/logout". If this is customized: The default log in & log out page are no longer provided The application must render a log in page at the provided URL The application must render an authentication error page at the provided URL + "?error" Authentication will occur for POST to the provided 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();
}
@inquisitive обновлен с помощью средства сопоставления выхода из системы, и оно работает нормально.
Вы можете совершить logoutUrl
, потому что вы переписываете его с помощью requiresLogout
У меня та же проблема, но я использую OAuth2Login, а приложение находится за обратным прокси-сервером с удалением префикса и использованием ForwardedHeaderTransformer
. Все работает хорошо, но страница выхода имеет жестко заданный путь /logout
, поэтому нет возможности добавить собственный префикс. И мое решение - изменить URL-адрес выхода из системы на /logout-oidc
http.logout(logout -> logout
.requiresLogout(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/logout-oidc"));
Плохо, что нет метода setLogoutPageGenerating(boolean enable)
отключающего LogoutPageGeneratingWebFilter
Я проверил, это полностью удаляет страницу выхода, но на самом деле не отвечает Как настроить securityWebFilterChain(ServerHttpSecurity http), чтобы мое приложение вышло из системы при GET/logout?