Apache Tomcat 7 Changing JSESSIONID on Every Request

雨燕双飞 提交于 2019-12-03 08:11:43

Turns out that it was cause by Spring Security. We are using Spring Security 3.1x, and by default it stores the authenticated credentials in the user's session. And to counter session fixation attacks, it automatically copies the contents of the user's session to a new session id and invalidates the old session.

The fix was to add the following to the http element in the security configuration, since we don't need to use the session in our application:

create-session="stateless"

Hopefully this helps someone else down the line.

I got the same problem with new id session when I refresh page On tomcat7 server, I only add into the context.xml this code :

<Valve className="org.apache.catalina.authenticator.BasicAuthenticator" changeSessionIdOnAuthentication="false" />

<Context path="/myapp" reloadable="false" override="true" useNaming="false" allowLinking="true" useHttpOnly="false" sessionCookiePath="/" sessionCookiePathUsesTrailingSlash="false">

This work fine for me.

Not sure exactly what your problem is, but there are two things I would check. First, did you specify the jvmRoute in tomcat?

Tomcat server.xml

<Engine name="Catalina" defaultHost="localhost" jvmRoute="machine1">

Haproxy.cfg (references jvmRoute)

server machine1 SERVER_IP cookie machine1 check 

Tomcat appends the name of the server to the cookie, so not setting that can cause issues.

The other thing to check is to make sure that you added this line to your web.xml in the web-app section

<distributable />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!