java - server.session.cookie.max-age 似乎不起作用
问题描述
我在我的配置中添加了以下属性:
server.session.cookie.max-age=3600
Set-Cookie
HTTP 标头是:
Set-Cookie: JSESSIONID=3407BD3E1C7153D70EFC5DBD16B059E4; Path=/; Secure; HttpOnly
所以看起来 Spring 忽略了这个属性。是否已弃用?如果没有,为什么它不起作用?
这是我的配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.successForwardUrl("/")
.defaultSuccessUrl("/", true)
.permitAll()
.and()
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)
.and()
.rememberMe()
.key("key")
.tokenValiditySeconds(86400);
}
解决方案
使用 Spring Boot 2.1.4,您必须使用属性server.servlet.session.cookie.max-age
而不是server.session.cookie.max-age
,请参阅Spring Boot 参考指南:
附录 A. 常见应用程序属性
可以在
application.properties
文件内、文件内application.yml
或作为命令行开关指定各种属性。本附录提供了常见 Spring Boot 属性的列表以及对使用它们的底层类的引用。[...]
# EMBEDDED SERVER CONFIGURATION (ServerProperties) [...] server.servlet.session.cookie.max-age= # Maximum age of the session cookie. If a duration suffix is not specified, seconds will be used.
推荐阅读
- python - 如何使用 psutil 与 python 建立实时 UDP 连接
- homebrew - 为什么 STS Cask 不适用于 macOS?
- node.js - 使用 nvm windows 安装 nodejs 时出现问题
- amazon-sns - 使用 Amazon SNS 的等宽字体
- python - 如何使用 python 的 pop 和 append 创建一系列变量列表?
- react-native - react-native run-ios 构建速度极慢
- tensorflow-serving - __saved_model_init_op 上的 TensorRT/Tensorflow2.0 转换失败
- c - 如何使用 Automake 编译和安装单个目标文件?
- javascript - Select2 - 选项项中的自定义输入字段,防止点击事件
- angular - 收到错误“https://localhost:44328/api/AllItProjectsLists/Index 的 Http 失败响应:0 未知错误”