gpt4 book ai didi

java - Spring 安全: Delete cookie for logout

转载 作者:行者123 更新时间:2023-12-01 16:49:18 25 4
gpt4 key购买 nike

我为我的 Spring boot 应用程序使用以下安全配置:

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/login").permitAll()
.and()
.authorizeRequests()
.antMatchers("/signup").permitAll()
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.logout().logoutUrl("/logout").logoutSuccessUrl("/login").deleteCookies("auth_code").invalidateHttpSession(true)
.and()
// We filter the api/signup requests
.addFilterBefore(
new JWTSignupFilter("/signup", authenticationManager(),
accountRepository, passwordEncoder),
UsernamePasswordAuthenticationFilter.class)
// We filter the api/login requests
.addFilterBefore(
new JWTLoginFilter("/login", authenticationManager()),
UsernamePasswordAuthenticationFilter.class)
// And filter other requests to check the presence of JWT in
// header
.addFilterBefore(new JWTAuthenticationFilter(userDetailsServiceBean()),
UsernamePasswordAuthenticationFilter.class);
}

当我注销时,我想删除登录期间设置的cookie。我使用 deleteCookie,但在 header 中没有删除登录期间设置的 cookie 的概念。为什么 ?

我应该如何告诉浏览器删除cookie?

现在,响应的 header 包含:

Set-Cookie →JSESSIONID=E4060381B435217F7D68EAAE82903BB0;path=/;Secure;HttpOnly

我应该将 cookie 的过期时间设置为当前日期之后的日期吗?

最佳答案

您不需要删除 cookie。一旦 session 在服务器上关闭,cookie 就无法再使用,并且如果用户返回,cookie 将被替换。只要让它正常过期即可(默认情况下,当浏览器关闭时)。

关于java - Spring 安全: Delete cookie for logout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43773840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com