4 Replies Latest reply on Sep 9, 2008 3:15 PM by wpernath

    Accessing multiple EJBs on different JBoss AS instances

    dkrizic

      Hello,

      I would to access two independent EJBs on two different JBoss instances, each is secured with a uniquely named SecurityDomain. Here is my authentication configuration:

      darko {
       org.jboss.security.ClientLoginModule required debug=true;
      };
      
      jochen {
       org.jboss.security.ClientLoginModule required debug=true;
      };
      


      Then I login to the first one (login 1)

       log.info("LoginContext [darko]");
       UsernamePasswordHandler uph = new UsernamePasswordHandler("darko",
       "test");
       LoginContext loginContext = new LoginContext("darko", uph);
       loginContext.login();
      
      


      Then I access the session bean (access 1):

       log.info("PersonService [darko]");
       PersonService ps = (PersonService) getService(PersonService.REMOTE_NAME);
       Person p = new Person(null, "Darko", "Krizic");
       p = ps.add(p);
       assertNotNull(p.getId());
       assertEquals(1, ps.listPersons().size());
       ps.update(p);
       ps.remove(p.getId());
       assertEquals(0, ps.listPersons().size());
      


      Then I login to the second JBoss instance (login 2)

       log.info("LoginContext [jochen]");
       UsernamePasswordHandler uph2 = new UsernamePasswordHandler(
       "jochen", "test2");
       LoginContext loginContext2 = new LoginContext("jochen", uph2);
       loginContext2.login();
      


      and then I access the second (technically identical) session bean (access 2)::

       log.info("PersonService [jochen]");
       PersonService ps2 = (PersonService) getService2(PersonService.REMOTE_NAME);
       Person p2 = new Person(null, "Jochen", "Grau");
       p2 = ps2.add(p2);
       assertNotNull(p2.getId());
       assertEquals(1, ps2.listPersons().size());
       ps2.update(p2);
       ps2.remove(p2.getId());
       assertEquals(0, ps2.listPersons().size());
      


      This works so far, but when I change the order from


      login 1
      access 1
      login 2
      access 2


      to

      login 1
      login 2
      access 1
      access 2


      The code does not work anymore. Obviously the login module is not able to handle this. What could I do? Would a separation in different classloaders work?

      Regards,

      Darko