如何在混合 Ruby/GWT 系统中管理会话?

发布于 2024-08-23 00:18:36 字数 641 浏览 6 评论 0原文

我目前有一个 Ruby on Rails 系统,并计划将其移植到 GWT。在我们这样做之前,主管部门希望获得概念验证,网站的一部分是用 GWT 编写的,以表明 GWT 可以使用和显示当前内容。系统 GWT 部分中的数据流如下:

  1. 客户端向 GWT 服务器发送 RPC 调用
  2. 服务器接收 RPC 调用,然后向 Rails 系统发出等效的 Ajax 请求
  3. 服务器根据 Ajax 的结果生成 Java 对象请求,将其传递回客户端

我现在遇到的问题是跨两个系统管理用户会话数据。我们只有 1 个 Tomcat 实例,并且有自己的会话类型,然后我们的 Ruby 系统使用 ActiveRecordStore 将会话数据存储在数据库中。

这里的问题是,当 Tomcat 系统与 Ruby 系统通信时,如果 GWT 客户端发出了登录请求,则最后一个从 GWT 系统登录的用户将在 Rails 系统中执行所有传出的 Ajax 请求,就好像它们'是当前用户,因为 Tomcat 系统看起来就像 Rails 的单个客户端。

无论如何,我怎样才能做到这样,如果用户开始与 Tomcat 系统进行会话,Ruby 系统将意识到这一点并拥有一个等效的会话,以便即使 Tomcat 服务器是它的单个客户端,Rails 系统意识到许多不同的用户正在从同一个客户端与其进行通信。

I currently have a Ruby on Rails system, and there are plans to port it to GWT. Before we do this, the powers that be want to have a proof of concept with part of the site being written in GWT to show that GWT can use and display the current content. The flow of data in the GWT portion of the system is as follows:

  1. Client sends an RPC call to the GWT server
  2. Server receives RPC call, then makes an equivalent Ajax request to the Rails system
  3. Server generates a Java object from the result of the Ajax request, passes it back to client

The issue I'm running into now is managing user session data across both systems. We only have 1 Tomcat instance, and that has its own type of sessions, and then our Ruby system uses ActiveRecordStore to store session data in the database.

The problem here is that when the Tomcat system talks with the Ruby system, if the GWT client has made a login request, the last user to log in from the GWT system has all outgoing Ajax requests being performed in the Rails system as if they're the current user since the Tomcat system looks like a single client to Rails.

Anyways, how can I make it such that if a user begins a session with the Tomcat system, the Ruby system will be aware of this and have an equivalent session so that even though the Tomcat server is a single client to it, the Rails system is aware of the fact that many different users are communicating with it from that single client.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ヅ她的身影、若隐若现 2024-08-30 00:18:36

我认为解决这个问题的最好方法是使用cookie而不是数据库来存储会话。 Rails 本身就支持这一点,实际上它已经成为默认的 cookie 存储一段时间了。 cookie 本身由服务器机密签名,以防止用户篡改。我认为 Rails 实现使用 Ruby 封送处理来转储/加载数据,因此您可能必须在 Java 中实现它,或者您可以使用相同的想法在两侧实现您自己的 cookie 管理器。

也可以在 Java 应用程序中仅使用 JRuby 中的 Ruby 代码。

I think the best way to solve this would be to use cookies instead of a database to store the session. Rails supports this natively, actually it's the default cookie store for some time now. The cookie itself is signed by a server secret to prevent user tampering. I think the Rails implementation uses Ruby marshaling to dump/load the data so you might have to implement it in Java, or you can implement your own cookie manager on both sides using the same idea.

It is also possible to just use the Ruby code from JRuby in your Java application.

请爱~陌生人 2024-08-30 00:18:36

我不知道 RoR,但在大多数网络技术中,会话都是使用 cookie 来维护的。如果您在从 Java 服务器到 RoR 实例的多次调用中保留 cookie(针对给定用户),那么您应该一切顺利。

I don't know about RoR, but in most web technologies sessions are maintained using cookies. If you preserve the cookies (for a given user) across multiple calls from your Java server to your RoR instance, you should be all good.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文