
Originally Posted by
fschroder
Hi, You're doing fine, now you just need to inject an implementation of RemoteInvocationExecutor to the exporter to deal with the extra attributes on the server side.
Federico.
Wahey! Good work
I now have it up and running:
I created a custom executor which I then injected it into the service exporter like this:
Code:
<bean id="customExecutor" class="rmipass.CustomExecutor"/>
...........
<property name="remoteInvocationExecutor" ref="customExecutor"/>
I then wrote an aspect that declares a pointcut to intercept the "invoke" method on this custom executor:
Code:
@Pointcut ("execution(* CustomExecutor.invoke(RemoteInvocation, Object))")
public void inRemote() {}
Finally I declare some advice to run before the invoke method is executed
Code:
@Before("inRemote() && args(invocation, ..)")
public void validateAccount(RemoteInvocation invocation) throws NotAuthorizedException {
final String user = (String) invocation.getAttribute("userName");
System.out.println("User name from client :- " + user);
if (user == null || !users.contains(user)) {
System.err.println("Not authorized :- " + user);
throw new NotAuthorizedException(user);
}
}
This advice has access to the the user name and checks if it is in some set of defined users, as read from DB or somewhere. If can then just return if user is authorized and the invoke will run as normal. Otherwise an exception is thrown back to client.
Using the @Before advice is following the "use the simplest thing that works idea"....could have used @Around but then I might forget to call proceed()!
Thanks for your help guys,
/Tom