0 Replies Latest reply on Nov 27, 2007 3:31 AM by Vasily Vasilkov

    Transparent login to JBoss Messaging

    Vasily Vasilkov Newbie

      env: JBoss 4.2.2 + JBoss Messaging 1.4

      problem: I have my own LoginModule. All beans and destinations are configured to use it. I have, for example, user with name "user", password "password" and role "role".

      When I need to invoke bean's method, I pass username/password through JNDI (SECURITY_PRINCIPAL/SECURITY_CREDENTIALS).
      When I need to work with some queue, I do login procedure look like this:

      InitialContext ctx = new InitialContext(<don't pass user/pwd here>);
      ConnectionFactory cf = (ConnectionFactory) ctx.lookup("/ConnectionFactory");
      Connection = cf.createConnection("user", "password"); // pass user/password here
      ..........................
      


      I do it from client and all works fine. But how I can work with JMS from bean? Now I make it like:
      @RolesAllowed(value="role")
      public void someBeanMethod() {
       String currentUser = sessionContext.getPrincipal().getName(); // username, who invoked this bean's method
       String password = getPasswordFromDatabase(currentUser); // get password from db
       InitialContext ctx = new InitialContext();
       ConnectionFactory cf = (ConnectionFactory) ctx.lookup("/ConnectionFactory");
       Connection = cf.createConnection(currentUser, password); // I don't want to do it!
       ..............
      }


      I don't want to do second login actions, because I have done one login when I invoked bean's method. How I can work with JBoss Messaging from bean's method with username/password, who invoked bean's method.


      P.S. Sorry for my english, I'm not native speaker.