0

I have a Java 8 web app running on a Tomcat 8 container that was deployed using AWS Elastic Beanstalk to an EC2 instance. I then configured Route 53 to point myapp.com to the Elastic Beanstalk endpoint as an alias, and did the same with www.myapp.com.

The problem is that when I login with either of them, the session is not shared with the other one. For example, if I login with myapp.com, and then try to access www.myapp.com, I'm being asked to login again. This problem is reproducible vice-versa and with the logout function too.

I've read this answer explaining the issue and while I understand the theory, I'm unsure on how to actually implement this. I tried pointing www.myapp.com directly to myapp.com as an alias on Route 53. I also tried configuring EB to use an Elastic Load Balancer and checked the Sticky Sessions option.

Is this something that can be configured on AWS or do I need to configure my code to accommodate this? An example would be really helpful. The application is a standard Enterprise Java web app with JSP and uses Spring Security for authentication.

Anish Sana
  • 478
  • 1
  • 10
  • 24

1 Answers1

2

Basically you need the Tomcat server to set domain="myapp.com" on every Set-Cookie header of every response.

There are many ways to do that. But the easiest way is to edit /src/resources/application.properties file in your application and set server.session.cookie.domain to myapp.com.

Scriptonomy
  • 3,641
  • 1
  • 11
  • 20