Sorry for the delay, I was going to have a look at this tonight and get back to you.

Jon

Sent from my iPhone

On 24 Sep 2009, at 13:47, Luis Fernando Planella Gonzalez <[email protected] > wrote:

Anyone on this, please?

It is critical for our application, as we need timers created with the
TimerService to run as a specific role, and this is a show stopper.

Perhaps I should post this in the developers list?

Luis Fernando Planella Gonzalez

Resending this mail, as It had attachments and was not published (at least
on nabble).
For the attachment, markmail did store the original post:
http://openejb.markmail.org/search/?q=type:users#query:type%3Ausers+page:1+
mid:2n47ayknj2uhniku+state:results

--- The original message ---
I'm trying to use @RunAs, however it does not work in tomcat + openejb.
Attached is a very simple example.
I was expecting the IndexServlet to print "Is admin? true", but it is
false. Either I'm missing something or there is a bug.
The code:

--- The servlet ---
public class IndexServlet extends HttpServlet {
       private static final long serialVersionUID = 1L;

       @EJB
       private RunAsService runAsService;

       protected void doGet(
               HttpServletRequest request,
               HttpServletResponse response)
               throws ServletException, IOException {

           response.setContentType("text/plain");
           PrintWriter out = response.getWriter();
           out.println("Is admin? " + runAsService.isAdmin());
           response.flushBuffer();
       }

}

--- The EJB interface ---
public interface RunAsService {

   boolean isAdmin();

}

--- The EJB implementation ---
@Stateless
@RunAs("admin")
@DeclareRoles("admin")
public class RunAsServiceBean implements RunAsService {

   @Resource
   private SessionContext sessionContext;

   @Override
   public boolean isAdmin() {
       return sessionContext.isCallerInRole("admin");
   }

}

--
Luis Fernando Planella Gonzalez

Reply via email to