我应该在什么时候更改 Struts 获取会话令牌的方式?

发布于 2024-08-19 18:16:50 字数 336 浏览 2 评论 0原文

看来我必须找到一种不同的方式来传输会话令牌 从 Flex 客户端到 Struts 后端,无需使用 cookie。

如果我要将会话令牌放入请求的有效负载中,那么我在什么时候必须自定义 Struts 的行为,以便可以尽可能多地重用现有的会话处理?特别是,我不想重新实现任何安全措施(例如将令牌绑定到 IP)和配置参数(例如会话过期间隔)。

有一个 CreateSession 拦截器,位于默认堆栈的早期,我应该将其与子类版本交换吗?

It seems I have to find a different way to transmit the session token from a Flex client to a Struts backend without using cookies.

If I were to put the session token in the payload of a request, at what point would I have to customize Struts' behaviour so that I can reuse as much of the existing session handling as possible? In particular, I don't want to reimplement whatever security measures (such as tying a token to an IP) and configuration parameters (such as session expiration interval).

There's a CreateSession interceptor, rather early in the default stack, should I swap that with a subclassed version?

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

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

发布评论

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

评论(1

难以启齿的温柔 2024-08-26 18:16:50

我对 Flex 的经验不是很丰富,但因为这看起来很有趣,而且我不喜欢看到问题得不到解答,所以我想尝试一下。据我了解,Flex 会话(HttpFlexSession)和 HttpSession 是完全独立的实体。也就是说,您应该能够在它们之间共享数据。

有一个非常相关的免费章节(第 20 章:Flex 与 J2EE 集成< /a>)可从 Steven Webster 和 Alistair McLeod 所著的《使用 Macromedia Flex 开发富客户端》一书中获取。

我现在将大量引用该免费章节!特别值得注意的是:

维持状态

理解上的最大飞跃
要做的是不再有
需要 HTTP 会话状态。虽然
您在富客户端和
服务器最终将被改造
HTTP,HTTP 已简化为
运输技术代替
我们需要整合的技术
和。 J2EE 开发人员很舒服
具有放置属性的概念
以及 HTTP 请求中的参数
响应对象,并维护
通过在 HTTP 中存储对象来获取状态
会议。 ...

... Flex 事实上可以提供对
HTTP 会话并允许 Flex
客户端将 HTTP 会话视为
“只是服务器上的另一个对象。”
然而,根据我们的经验,使用
HTTP 会话应该是“难闻的气味”
标识重构
有机会改变你的一些
将应用程序状态传输到客户端。

本章稍后将向您展示如何配置 Flex 客户端访问的会话对象。

获得对 J2EE 会话的访问

Flex 预配置会话 servlet
在默认的 web.xml 文件中,
提供服务器端 Java
可用于访问和
修改 J2EE 会话
应用。通过放置其中之一
以下远程对象定义在
我们的服务定位器位于 services.mxml,
我们为我们的应用程序提供了
可以获取和设置对象的服务
在 J2EE 会话中,以及删除
会话中的对象:

<mx:Remote object source="servlet" id="sessionObject" /> 
<mx:Remote object source="@ContextRoot()" id="sessionObject"/>

与任何其他一样
标签,会话服务可以使用
结果和故障事件处理程序
处理从中获取项目的请求
会议。 web.xml 描述符
定义会话的名称
servlet 作为 servlet;因此,我们使用
以下示例之一可以工作
与 J2EE 会话:

sessionObject.session( "set","customerID", 700 );
sessionObject.session( "get", "customerID" ); 
sessionObject.session("remove", "customerID" );

这三个示例演示了如何
会话服务用于获取,
设置或删除 J2EE 中的项目
来自 Flex 客户端的会话。

因此,虽然您可以在 Flex 和后端 Java 之间共享会话数据,但是,建议似乎是这是一种反模式

关于安全措施,如果您使用 Servlet Filters 来实现 IP 限制,那么您的安全性可以应用于 Web 应用程序中的所有资源(无论它是 Struts 还是 Flex 来源)。

I'm not very experienced with Flex but as this seemed interesting and I do not like to see questions go unanswered I thought I would have a stab at it. As I understand it the Flex session (HttpFlexSession) and the HttpSession are completely separate entities. That said you should be able to share data between them.

There is a very relevant free chapter (Chapter 20: Flex Integration with J2EE) available from the book "Developing Rich Clients with Macromedia Flex" by Steven Webster and Alistair McLeod.

I will now quote heavily from that free chapter! Of particular note:

Maintaining State

The biggest leap in understanding to
be made is that there's no longer a
need for HTTP session state. Although
your requests between rich client and
server are ultimately being made over
HTTP, HTTP has been reduced to a
transport technology instead of a
technology that we need to integrate
with. J2EE developers are comfortable
with the concept of placing attributes
and parameters in the HTTP request and
response objects, and maintaining
state by storing objects in the HTTP
session. ...

... Flex can in fact offer access to
the HTTP session and allow the Flex
client to treat the HTTP session as
"just another object on the server."
However, in our experience, using the
HTTP session should be a "bad smell"
that identifes a refactoring
opportunity to shift some of your
application state onto the client.

Later on in this chapter it shows you how to configure the session object for Flex client access.

Gaining Access to J2EE Sessions

Flex preconfigures a session servlet
in the default web.xml file, which
makes available a server-side Java
object that can be used to access and
modify the J2EE session for an
application. By placing one of the
following Remote object definitions in
our Service Locator at services.mxml,
we make available to our application a
service that can get and set objects
in the J2EE session, as well as remove
objects from the session:

<mx:Remote object source="servlet" id="sessionObject" /> 
<mx:Remote object source="@ContextRoot()" id="sessionObject"/>

As with any other <mx:RemoteObject>
tag, the session service can use
result and fault event handlers to
handle requests to fetch items from
the session. The web.xml descriptor
defines the name of the session
servlet as servlet; therefore, we use
one of the following examples to work
with the J2EE session:

sessionObject.session( "set","customerID", 700 );
sessionObject.session( "get", "customerID" ); 
sessionObject.session("remove", "customerID" );

These three examples demonstrate how
the session service is used to get,
set, or remove items in the J2EE
session from a Flex client.

So it would seem that although you can share session data between Flex and backend Java, however, the suggestion seems to be that this is an anti-pattern.

With respect to security measures, if you were using Servlet Filters to implement IP restriction then your security could be applied to all the resources in your web application (irrespective of whether it was of Struts or Flex origin).

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