Two Spring Security local project login conflicts

The problem arises
because I want to be a resource authentication server recently, and I have started two projects that integrate Spring Security. After opening loginPage("/portal/login"), I found a problem when logging in: port 8085 project A and port 8080 The item B cannot be logged in at the same time. If A logs in, B will refresh the login status of A when he logs in again.

Cause of the problem
After some research, the reason is that the session saves a cookie in the browser to identify the session. It seems that there is no problem, but the cookie does not distinguish the port number, and the cookie is shared under the same ip.
In other words, our local projects are all localhost, the domain name is the same, and the port number is different. But they all share a cookie, which causes the cookies used by the two projects to log in to overwrite each other.

Solution
We can configure different domain names in the hosts file, and access our local projects through different domain names. Such as:

127.0.0.1    www.qbq.com
127.0.0.1    www.aaa.com

1
2
we can access www.qbq.com:8085,www.aaa.com:8080 respectively. In this way, their cookies will not conflict
————————————————
Copyright statement: This article is the original article of CSDN blogger "Madtuquan", following CC 4.0 BY-SA copyright Agreement, please attach the original source link and this statement for reprinting.
Original link: https://blog.csdn.net/a624193873/article/details/106417085

Guess you like

Origin blog.csdn.net/weixin_38019299/article/details/107085453