Reputation: 133
What is the equivalent way to invalidate session and delete cookies in WebFlux when doing logout similar to
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception
{
http
.httpBasic()
.and()
.logout().clearAuthentication(true)
.logoutSuccessUrl("/")
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)
.and()
...
Upvotes: 5
Views: 3362
Reputation: 1602
Besides that the cookie "SESSION" and the WebSession (session name in WebFlux) are removed by default, you can configure a ServerLogoutSuccessHandler:
.logout()
.logoutSuccessHandler(new ServerLogoutSuccessHandler() {
@Override
public Mono<Void> onLogoutSuccess(WebFilterExchange exchange, Authentication authentication) {
ServerHttpResponse response = exchange.getExchange().getResponse();
response.setStatusCode(HttpStatus.FOUND);
response.getHeaders().setLocation(URI.create("/login.html?logout"));
response.getCookies().remove("JSESSIONID");
return exchange.getExchange().getSession()
.flatMap(WebSession::invalidate);
}
})
Upvotes: 4