2 Replies Latest reply on Apr 22, 2010 9:03 AM by waldschrat

    Security problem - sending JMS Message changes SecurityContext

      Hi!

       

      We migrated our applicaton from JBoss 4.0.5GA to  5.1.0GA and encounter a strange security-problem.

       

      Our beans have a custom SecurityDomain "SadBasisSecurityDomain" and most bean-methods require at least the caller to have the role "SAD_User".

      Everything works fine, except some special cases: some bean-methods need to send JMS-messages and call other secured bean-methods afterwards. These calls fail with the message "Caller unauthorized".

       

      After debugging i found that this:

       

           TopicConnectionFactory fact = (TopicConnectionFactory) ctx.lookup( "ConnectionFactory" );
           TopicConnection connection = fact.createTopicConnection();

       

      switches the SecurityContext to the SecurityDomain "messaging" with no principal and no roles. The SecurityContext is never switched back to the initial SecurityContext before creating the TopicConnection. Subsequent call of our secured bean-method fails.

       

      This worked with JBoss 4.0.5GA.

       

      My question is: is this a bug or are we doing something wrong?

       

      I found https://jira.jboss.com/jira/browse/HORNETQ-340 , wich seems to describe a similar problem.

       

      We hacked a workaround. Before sending a JMS-message we save the SecurityContext

       

           SecurityContext context = SecurityContextAssociation.getSecurityContext();

       

      ...and programmatically switch back after sending the JMS-message

       

           SecurityContextAssociation.setSecurityContext( context );

       

      But this cannot be the solution...

       

      Could anyone help us please?