在 Spring 拦截器中访问 DWR 发布数据

发布于 2024-07-22 06:33:00 字数 473 浏览 2 评论 0原文

我有一个带有方法签名的 DWR 操作,如下所示:

String joinGroup(String groupId, String groupName);

这是通过 DWR AJAX 请求调用的,并且工作正常。

但是,我正在尝试编写一个 Spring 拦截器(工作方式与 ServletFilter 非常相似)来在调用 DWR 操作之前执行一些身份验证工作。
拦截器被正确调用,但我需要访问拦截器中的 groupId 和 groupName 数据。

请求参数映射为空,我已经在调试器中浏览了整个请求属性列表,但在任何地方都看不到数据。
请求的 postData 也为 null。

使用 firebug 我可以看到数据正在传递到服务器(当最终调用 joinGroup 方法时它就在那里)。
我似乎无法在拦截器中访问它。

我有什么办法可以访问它吗?

I have a DWR action with a method signature as follows:

String joinGroup(String groupId, String groupName);

This is called via a DWR AJAX request and works fine.

However, I am trying to write a Spring interceptor (works much like a ServletFilter) to do some authentication work before the DWR action is called.
The interceptor is being called correctly but I need to access the groupId and groupName data in the interceptor.

The request parameter map is empty and I've been through the entire list of request attributes in a debugger and I can't see the data anywhere.
The request's postData is null also.

Using firebug I can see the data is being passed to the server (and it's there when the joinGroup method is ultimately called).
I just can't seem to access it in my interceptor.

Is there any way I can access it at all?

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

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

发布评论

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

评论(2

琴流音 2024-07-29 06:33:00

使用 org.directwebremoting.AjaxFilter

每次在配置此过滤器的方法上发出 Ajax 请求时,DWR 都会调用 AjaxFilter 的 doFilter 方法。 传入此方法的 AjaxFilterChain 允许过滤器将方法详细信息传递到链中的下一个实体。

通常,该方法将执行以下操作:

  1. 检查请求
  2. (可选)更改方法、对象或参数
  3. 使用 AjaxFilterChain 调用链中的下一个实体,或者决定采取其他操作。
  4. (可选)修改返回给用户的值
  5. 采取其他一些操作(例如日志记录)

Use org.directwebremoting.AjaxFilter

The doFilter method of the AjaxFilter is called by DWR each time an Ajax request is made on a method that this filter is configured against. The AjaxFilterChain passed in to this method allows the filter to pass on method details to next entity in the chain.

Typically the method would do the following:

  1. Examine the request
  2. Optionally alter the method, object or parameters
  3. Either invoke the next entity in the chain using the AjaxFilterChain or decide to take some other action instead.
  4. Optionally modify the value returned to the user
  5. Take some other action (e.g. logging)
春夜浅 2024-07-29 06:33:00

我假设您使用 MethodInterceptor ,它仅在上述方法上被调用(意味着您的配置是正确的)。

...
@Override
public Object invoke(MethodInvocation inv) throws Thorwable {
   Object[] args = inv.getArguments();
   String groupId = args[0];
   String groupName = args[1];
   .... if user has access call inv.proceed, else throw AccessDeniedException
}

Spring框架中的MethodInterceptor与Spring Security中的MethodSecurityInterceptor几乎完全相同。

I will assume you you using a MethodInterceptor which is getting called (meaning your config is correct) only on the above method.

...
@Override
public Object invoke(MethodInvocation inv) throws Thorwable {
   Object[] args = inv.getArguments();
   String groupId = args[0];
   String groupName = args[1];
   .... if user has access call inv.proceed, else throw AccessDeniedException
}

MethodInterceptor in the Spring Framework is pretty much the exact same as MethodSecurityInterceptor in Spring Security.

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