Reputation: 143
I currently am using Spring Integration to get messages off of a queue and send them to a service using a service activator. My issue is that the service I am calling requires a security context to be in place for the current thread. This can be setup by calling a no-argument method, handleAuthentication(), of another bean. I am wondering what the best way is to call this whenever a new message is received, prior to calling the service activator service? I was originally thinking I would chain together two service activators, with the first one calling handleAuthentication(), but this seems incorrect as handleAuthentication() does not require any information from the actual message.
Upvotes: 1
Views: 70
Reputation: 121552
Yes, your assumption about the security handling is correct. It is really just a side-effect aspect which should not be tied with the business logic.
Therefore we should use something which allows us to follow with the same behavior in the program. It is called as an Aspect
in the programming as well.
For this purpose Spring Integration suggests a hook like MessageChannelInterceptor
, where you can implement your handleAuthentication()
exactly in the preReceive()
callback, according to your explanation.
Another trick can be achieved with the <request-handler-advice-chain>
and MethodInterceptor
implementation which should populate the SecurityContext
into the current thread just before target service invocation.
Upvotes: 1