java - 如何在 Spring Boot 中将 SAMESite cookie 设置为 none?
问题描述
我在两 (2) 个不同的服务器上部署了带有 reactjs(frontEnd) 和 springboot(Backend) 的 Web 应用程序。
它们都是http 服务器而不是 HTTPS。
我搜索了所有与此相关的 stackoverflow 问题,但似乎没有一个有效。
我没有使用spring-session依赖或Spring-security依赖。
为了维护用户会话,我只是让我的豆子@SessionScoped,如果一切都在同一台服务器上,它工作正常,但在不同的服务器上它已经坏了。
浏览器给出了这个错误,因为can't set samesite=none, over http for this https is required。
那么这个问题的解决方法是什么。因为我现在不能让我的服务器成为 https 。
解决方案
我使用 ResponseCookie 解决了这个问题。见下文:
final ResponseCookie responseCookie = ResponseCookie
.from("test", "test")
.secure(true)
.httpOnly(true)
.path("/")
.maxAge(12345)
.sameSite("None")
.build();
response.addHeader(HttpHeaders.SET_COOKIE, responseCookie.toString());
Cookie 名称:test 和值:test。
需要设置安全 true 才能使用 sameSite("None")。
这应该可以保存您的 Cookie
推荐阅读
- arrays - 如何从 Swift 中的数组以编程方式在堆栈中创建按钮
- ruby - 是否有可能使用 Ruby+Minitest 编写参数化测试?
- pandas - tf.keras.model.fit 需要很长时间
- php - 在产品页面 Opencart 3 上显示类别
- python - 有没有办法使用 pyswip 和 Flask?
- python - 不符合 Python 变量限制的 Scrapy 字段名称
- python - 如何从python中的列表中删除撇号?
- r - 使用循环和条件管理数据框
- php - Laravel/PHP:包含(.../Controller.php):无法打开流:权限被拒绝
- php - 插入递归数组?