6 Replies Latest reply on Aug 16, 2013 9:29 AM by jaikiran

    Login from Timerbean

    podiki

      I've got a timer bean that starts up a batch job by calling another EJB. I want the batch to run under a certain user so I've tried to set this up. I have tried two ways of setting this up. One way is by doing a context lookup of the bean doing the batch. I also tried it by setting up a jboss-ejb3.xml where I specify a role-name and a run-as-principal, but both methods don't seem to work. Which of these two ways would be the preferable way and does anybody have a working example of this? The problem I'm having is that the batch is always run as user anonymous.

        • 1. Re: Login from Timerbean
          jaikiran

          Use @RunAsPrinicipal or @RunAs (depending on your need) on the Timer bean which invokes the batch bean.

          • 2. Re: Login from Timerbean
            podiki

            I thought those didn't work in JBoss 7.x. Ok, I will try them out.

             

            I don't seem to have @RunAsPrincipal though. In what package is this annotation? And what maven dependency would that be? As I can only find it in  'jboss:jboss-annotations-ejb3:4.2.2.GA' which doesn't look good to me...

             

            Thank you for your response.

            • 3. Re: Login from Timerbean
              jaikiran

              org.jboss.ejb3:ejb3-ext-api is the Maven co-ordiante and the fully qualified annotation names are @org.jboss.ejb3.annotation.RunAsPrincipal and @org.jboss.ejb3.annotation.@RunAs

              1 of 1 people found this helpful
              • 4. Re: Login from Timerbean
                podiki

                @RunAsPrincipal is in that package, but @RunAs isn't.

                 

                 

                An EJB that is annotated with @RunAsPrincipal, can I just get a reference with @EJB? Or do I have to do a context lookup?

                • 5. Re: Login from Timerbean
                  jaikiran

                  jaikiran pai wrote:

                   

                  and @org.jboss.ejb3.annotation.@RunAs

                  Sorry that's a typo. That should be @javax.annnotation.security which is part of Java EE and not specific to JBoss.

                  1 of 1 people found this helpful
                  • 6. Re: Login from Timerbean
                    jaikiran

                    Podiki Stifado wrote:

                     

                     

                     

                     

                    An EJB that is annotated with @RunAsPrincipal, can I just get a reference with @EJB? Or do I have to do a context lookup?

                    The presence or absence of @RunAsPrincipal on a EJB doesn't change the way you get hold of the EJB. So both @EJB and a manual lookup should work irrespective of whether or not that annotation is used.