gwt rpc 中的会话 ID cookie

发布于 2024-08-03 11:14:57 字数 167 浏览 2 评论 0原文

假设我正在滚动自己的会话代码,那么在 java 中生成唯一且安全的会话 id cookie 的正确方法是什么?

我不应该自己推出而是使用已经标准化的东西吗?

我正在使用 gwt 和 google app-engine 平台。

如何使会话在浏览器/服务器重新启动后持续存在?

Assuming I'm rolling my own session code, what's the right way to generate a unique and secure session id cookie in java.

Should I not be rolling my own but using something that's already been standardized?

I'm using gwt and the google app-engine platform.

How do I make sessions persist across browser/server restarts?

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

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

发布评论

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

评论(3

少女净妖师 2024-08-10 11:14:57

在 GWT 中使用 Servlet Session

在远程服务实现类中:

String jSessionId=this.getThreadLocalRequest().getSession().getId();

在客户端代码中:

String jSessionId=Cookies.getCookie("JSESSIONID");

Enabling_Sessions

appengine-web.xml

<sessions-enabled>true</sessions-enabled>

Using Servlet Sessions in GWT

In the remote service implementation class:

String jSessionId=this.getThreadLocalRequest().getSession().getId();

In the client code:

String jSessionId=Cookies.getCookie("JSESSIONID");

Enabling_Sessions

appengine-web.xml

<sessions-enabled>true</sessions-enabled>
小嗲 2024-08-10 11:14:57

不,你不应该自己动手。

会话 ID 需要是加密随机的(无法从已知来源猜测)。自己很难做到这一点。

No, you shouldn't be rolling your own.

The session ID needs to be cryptographically random (not guessable from known sources). It's difficult to get this right yourself.

逆流 2024-08-10 11:14:57

理想情况下,您应该依赖底层框架的会话管理功能。 Servlet 和JSP、Struts 和 Spring 都提供这种支持,您应该使用它们。

在极少数情况下,您正在编写自己的框架,而没有可依赖的底层会话管理功能,则可以从 java.security.SecureRandom 类开始。当然,不要在这里重新发明轮子,因为损坏的会话管理与损坏的身份验证相同。

更新

鉴于您使用的是 Google App Engine,您应该依赖该引擎提供的会话管理功能。 默认情况下似乎未开启

Ideally you should be relying on the underlying framework's session management features. Servlets & JSPs, Struts and Spring have this support, which you should use.

In the extremely rare case that you are writing your own framework with no underlying session management features to rely on, you could start with the java.security.SecureRandom class to begin with. Of course, don't reinvent the wheel here, for broken session management is the same as broken authentication.

Update

Given that you are using Google App Engine, you should rely on the session management features provided by the engine. It seems that it is not switched on by default.

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