2 Replies Latest reply on Oct 29, 2013 8:39 AM by anzorishe

    @RunAsPrincipal not working ?

    jw

      @RunAsPrincipal is not working as I understand it (what might be wrong)

       

      Having the this code:

       

      {code:java}

      @Stateless

      public class MyTimer {

       

          @EJB

          private MyBeanWrapper wrapper;

       

          @Schedule(hour = "*", minute = "*", second = "0/5")

          public void onTimeout() {

              wrapper.printIdendity();

          }

      }

       

       

       

      @Stateless

      @RunAs("TEST")

      @RunAsPrincipal("test")

      public class MyBeanWrapper {

       

          @EJB

          private MyBean bean;

       

          public void printIdendity() {

              bean.printIdendity();

          }

      }

       

       

      @Stateless

      public class MyBean {

       

          @Resource

          private SessionContext ctx;

       

          public void printIdendity() {

              System.out.println("Caller identity is " + ctx.getCallerPrincipal().getName());

              System.out.println("Has role TEST is " + ctx.isCallerInRole("TEST"));

          }

      }

      {code}

       

       

      I would expect an output like

       

      15:02:50,030 INFO  [stdout] (EJB default - 9) Caller identity is test

      15:02:50,031 INFO  [stdout] (EJB default - 9) Has role TEST is true

       

       

      but I get

       

      15:02:50,030 INFO  [stdout] (EJB default - 9) Caller identity is anonymous

      15:02:50,031 INFO  [stdout] (EJB default - 9) Has role TEST is true

       

       

      Is this the expexted behaviour, a bug or just wrong usage of this annotation?