Results 1 to 5 of 5

Thread: Acegi & JMS

  1. #1
    Join Date
    Aug 2004
    Posts
    229

    Default Acegi & JMS

    Has anyone done anything with Acegi and JMS? Specifically, we want the Acegi security context to be all properly setup by the time a message listener is invoked. I'm thinking we will have to include information in the message itself (probably in the message headers) to setup the security context and then intercept the listener interface and do context setup before invoking the actual listener method. Do you suppose this is the right track? At the moment, I'm kind of a newbie to JMS, and have only a working knowledge of Acegi. I guess that passing the username/password around in the message header is not too secure, so we will probably have to come up with a session or token system?
    Any tips or advice would be greatly appreciated.

    - Andy

  2. #2
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    A key issue with a session or token system is the lifespan of the message. You could use the existing CAS token system, which is robust and proven, if the messages will only exist for a period less than EhCacheBasedTicketCache.minutesToIdle (or write your own implementation of StatelessTicketCache).

    In terms of the JMS-specific presentation of the username and password, could you write an interceptor which is fired for every message (like a Servlet Filter) which unwraps the message, looks at the username and password, sets the ContextHolder, proceeds with the message, then sets the ContextHolder to null?

  3. #3
    Join Date
    Aug 2004
    Posts
    229

    Default

    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

  4. #4
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Sounds like a helpful template class for certain environments. Perhaps passing in the target Authentication request (ie populated principal and credentials) would be better than the Context. The Context the template class creates would default to SecureContextImpl, or an alternative callback could be used that also specified the target implementation class.

    In relation to the JMS side of things, I agree your approach sounds the most promising at this point. If you find it works, and particularly if you implement it via a template as proposed, I'd welcome the code as it would be a worthwhile addition to CVS nw that JMS is a part of Spring Core.

  5. #5
    Join Date
    Aug 2004
    Posts
    229

    Default

    I'm going to try and work on it some today. I'll move any further discussion to the Acegi development list.

    - Andy

Similar Threads

  1. Replies: 8
    Last Post: Mar 19th, 2008, 11:13 AM
  2. Acegi running fine. Howto add roles, ...
    By ThomasBecker in forum Security
    Replies: 9
    Last Post: Sep 16th, 2007, 08:16 AM
  3. Replies: 9
    Last Post: Sep 5th, 2006, 06:50 AM
  4. Acegi for LDAP
    By vaibhav.gandhi in forum Security
    Replies: 12
    Last Post: Jul 13th, 2005, 12:33 AM
  5. Replies: 4
    Last Post: Nov 2nd, 2004, 02:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •