0

对于 SaaS 应用程序,同一台服务器托管多个应用程序。会话属性如何维护?为了详细说明问题:AppA 和 AppB 托管在同一台机器上,我现在为 AppA 创建 UserA,为 AppB 创建 UserB。AppA 和 AppB 属于不同的组织,因此它们没有关联。有关用户的一些详细信息存储在 http 会话级别(直到会话超时)。因此,现在如果我使用不同的选项卡从同一浏览器同时登录 AppA 和 AppB,我最终可能会在 UserB/AppB 屏幕上看到一些 UserA/AppA 详细信息,反之亦然。如何解决这样的问题?我能想到的一种解决方案是创建像 appa.example.org 和 appb.example.org 这样的子域。还有其他/更好的方法吗?

4

2 回答 2

1

The best solution I've come up with was inspired by this question. I've pointed multiple contexts to the same war file:

<Service ...>
    <Engine ...>
        <Host ... autoDeploy="false">
            <Context docBase="myapp.war" path="/tenant1"/>
            <Context docBase="myapp.war" path="/tenant2"/>
        </Host>
    </Engine>
</Service>

This is essentially the same as making copies of myapp.war called tenant1.war, tenant2.war, etc. Each tenant is technically running thier own webapp, even though they're all running the same code. If you have users with credentials on two or more tenants, they can log on to both at the same time, and each webapp will get its own session, because the JSESSIONID cookies containing the session ID are each tied to a specific context path.

There are drawbacks to this approach. For one, all the classes in the war file get reloaded for each tenant, so I'll have to keep an eye on PermGen space. For another, I'll have to edit server.xml every time a new tenant comes along. Have you found a better solution?

于 2012-06-07T16:05:49.363 回答
1

通常,您不会在另一个应用程序中看到一个应用程序的详细信息。

创建会话时,它会在 Web 应用程序内部创建并由密钥标识。这个 session-id 存储在 cookie 中或以其他方式传递,以识别在下一个请求中引用哪个会话对象。

如果您将此会话 ID 呈现给另一个 web 应用程序,它将找不到属性,因为它们存在于另一个 web 应用程序中。

现在,那是“通常”。实际上,这可以在各个方向进行配置,例如将所有属性存储在 cookie 中(在极端故障转移场景中非常有用),将会话存储在共享的 memcached 层或共享数据库表中(然后您将在另一个中获取相同的对象当然是应用程序),等等,等等。

于 2010-09-02T09:18:33.790 回答