Good point about the session timeout. So, from an implementation standpoint, it looks like the easiest thing is to pass username and password around. I wonder how secure this is? What if someone with a queue browser is poking around - even if this person is an admin, I still wouldn't want him/her seeing other people's passwords.
Just thinking out loud here, I'm not sure if I could find an automagic way to intercept every message... at least, I'm not sure if the JMS spec provides a way to do this. The interception would have to happen just before the message is delivered to ensure it is intercepted in the same thread as the listener. Because of this, for listener consumers anyway, it would probably have to be done by intercepting the developer's actual listener implementation. In other words, I would use Spring to create my bean instance that implements the JMS listener interface, and then use Spring to wrap that bean instance in an aspect that intercepts the 'onMessage' method on the listener interface and sets up the Context before allowing the listener method invocation to proceed. For "pull" style use (where my client code asks JMS to give it the next message, if any) I would either have to wrap the MessageConsumer interface returned from JMS with an aspect, or invoke a special "helper" method after getting the message and before processing. Because I'm only going to use the listener style in my code, that's all I'm going to worry about for now. :-)
One thought I had that might make this kind of thing a little easier is an Acegi context "template" that works something like Spring's Hibernate template:
Code:
acegiContextTemplate.execute(authentication,
new AcegiCallback() {
public Object doInSecurityContext(Context context) {
...
}
}
);
This template would automatically process the authentication and setup the context in ContextHolder. The Context passed into 'doInSecurityContext' is just for reference. Thoughts?
- Andy