如何在 tomcat 服务器上为我的 spring 项目设置 session cookie 属性“Domain”?我正在使用 spring security 和 HTTPS 目前我有以下内容:
Set-Cookie: JSESSIONCookie: JSESSIONID=DEAC4422AB4E28A7062C08724C8BCFAA; Path=/myapp/; Secure; HttpOnly.
但是我想要这个
Set-Cookie: JSESSIONCookie: JSESSIONID=DEAC4422AB4E28A7062C08724C8BCFAA; Path=/myapp/; Secure; Domain=.localhost; HttpOnly.
我尝试使用 cookie-config 将域属性放入 web.xml 中。 我试过使用 spring session [CookieHttpSessionStrategy],但这不起作用。
有类似 TomcatContextCustomizer 的东西,但它不起作用 [实际上我可能在配置它时犯了一些错误]
此外,如果在本地主机上运行,我应该设置什么域?
obj.setDomain("localhost");//or
obj.setDomain(".localhost");//or
obj.setDomain("127.0.0.1");
以上哪一项是正确的?
最佳答案
您可以使用 tomcat 配置属性:sessionCookieDomain
The domain to be used for all session cookies created for this context. If set, this overrides any domain set by the web application. If not set, the value specified by the web application, if any, will be used.
<context sessionCookiePath="/myapp/" sessionCookieDomain=".localhost">
...
</context>
在全局配置 config/context.xml
或特定于应用程序的上下文文件中。
关于java - 在 java-spring-tomcat 上设置 session cookie 属性 "Domain",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34808694/