1 Reply Latest reply on Sep 21, 2012 4:46 PM by grossetieg

    Testing secured EJB on JBoss AS 7.1.1 with RunAsIdentity

    grossetieg

      Hi,

       

      I read carefully the post https://community.jboss.org/wiki/TestingSecuredEJBsOnJBossAS71xWithArquillian but in my case I don't want to use my LoginContext just a simple RunAsIdentity.

      As far as I understand my test will be executed in the container but the following code isn't working :

       

      final RunAsIdentity runAs = new RunAsIdentity("ADMIN", "admin");
      SecurityContextAssociation.pushRunAsIdentity(runAs);
      
      

       

      In my class under test when I retrieve the CallerPrincipal I get anonymous :

       

      @Resource
      private SessionContext sc;
      

       

      sc.getCallerPrincipal().getName()
      

       

      Am I missing something ? Is this suppose to be working ? If you want I can provide a simple test case to reproduce this behavior.

       

       

      Thanks,

      Guillaume.

        • 1. Re: Testing secured EJB on JBoss AS 7.1.1 with RunAsIdentity
          grossetieg

          With some debug, I found a workaround :

          final JBossSecurityContext securityContext = new JBossSecurityContext("other");
          SecurityContextAssociation.setSecurityContext(securityContext);
          securityContext.setIncomingRunAs(new RunAsIdentity("ADMIN", "admin"));
          

           

          The security context was null so I had to create and set one. I also had to manually set the IncomingRunAs on the security context because the propagation wasn't trigger (SecurityContextInterceptor) and as a consequence the IncomingRunAs (CallerPrincipal) wasn't fill with the RunAsIdentity (OutgoingRunAs) ?

          Hope it can help

           

           

          Guillaume.