views:

523

answers:

2

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?

+1  A: 

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.

Gandalf
Hiya, am not using acegi I'm afraid.I have figured out an alternative solution anyway which I will post shortly.
Darren Greaves
Ah, when I saw the word "authentication" I figured you were using Spring Security or Acegi.
Gandalf
Same idea...just use Spring AOP to intecept the method call
Gareth Davis
+1  A: 

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)
Pavitar Singh
This was the solution I found after posting the question, thanks.
Darren Greaves