我有两个不同的应用程序,例如 A
和 .两者都使用具有相同配置的 Spring Security。这是我的情况:
我登录到我的 A
应用程序。一切正常。但是,当我在同一浏览器的另一个选项卡中登录我的 B
应用程序(它具有相同的 IP 但不同的端口)时,我看到这些行(如下),并且我被 A 抛弃了
应用程序,这意味着我不再在其中进行身份验证。
DEBUG 2013-05-20 13:42:43,969 [http-8080-2] org.springframework.security.web.FilterChainProxy$VirtualFilterChain : /webapp/backoffice/index.jsp at position 2 of 12 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
DEBUG 2013-05-20 13:42:43,969 [http-8080-2] org.springframework.security.web.context.HttpSessionSecurityContextRepository : No HttpSession currently exists
DEBUG 2013-05-20 13:42:43,969 [http-8080-2] org.springframework.security.web.context.HttpSessionSecurityContextRepository : No SecurityContext was available from the HttpSession: null. A new one will be created.
- 我使用
HttpSessionSecurityContextRepository
作为 SecurityContextRepository。 - 出于安全目的,我启用了SessionMigration。
- 我正在使用ConcurrentSessionFilter来防止某人通过两个或更多设备登录。
但我不明白为什么登录我的 B
应用程序会从 A
应用程序中删除 HttpSession? (或者可能发生了其他一些事情)
我想知道这些应用程序在浏览器中是否有一些共同点。
<小时/> 当我被问及他们的 IP/端口时,你应该知道他们的 IP 是相同的(都是本地主机),但他们有不同的端口。A)
localhost:8080/dtts/backofficeB)
localhost:8081/dtts/backoffice
<小时/>
已解决问题是对于每个
URL/Path
都会有一个唯一的 JSESSIONID
。我的两个应用程序都使用 URL:localhost
和 Path:dtts
。这就是为什么第二个 JSESSIONID
取代了第一个。
最佳答案
来自应用程序 B 的 cookie 会覆盖应用程序 A 浏览器中存储的 cookie,因为这两个 cookie 来自同一服务器,即“localhost”,并且两个 cookie 都有名称,即“JSESSIONID”。
Cookie 不特定于端口。这在这个问题中进行了讨论:Are HTTP cookies port specific?
我相信您的选择是:
- 使用不同的 IP 或服务器名称来访问每个应用程序(例如 localhost 和 127.0.0.1,或 applicationA.mydomain.com 和 applicationB.mydomain.com)
- 为 session 使用不同的名称 每个应用程序运行的容器中的 cookie
关于java - 具有 spring security 的应用程序之间是否共享 SecurityContextHolder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16646528/