0 Replies Latest reply on Feb 13, 2013 9:00 AM by Juergen Weber

    Cannot use different EJB client Users

    Juergen Weber Novice

      You can invoke an EJB with an InitialContext and a SECURITY_PRINCIPAL as described here:



      Now I tried to simulate different users and ran a loop with changing InitialContexts and SECURITY_PRINCIPALs.

      Surprisingly the EJB's getCallerPrincipal() always returns the user that was used for the first new InitialContext(), the following are ignored.

      What can I do to make this work?


      Thx, Juergen


      for (String user : users.keySet())


          String pass = users.get(user);


          jp.setProperty("java.naming.security.principal", user);

          jp.setProperty("java.naming.security.credentials", pass);




          InitialContext initialContext = new InitialContext(jp);


          Object o = initialContext.lookup(n);


          Chained1 ejb = (Chained1) o;

          String s = null;

          for (int i = 0; i < 1; i++)


              s = ejb.secureMethod("client");


          System.out.println("Got: " + s);



      One example output of the Properties is

      {java.naming.provider.url=remote://myhost:4447, java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory, java.naming.security.principal=jboss, jboss.naming.client.ejb.context=true, java.naming.security.credentials=yyy}