I think you need to do the RunAs on the servlet itself, rather than on the
EJB. I've knocked up a sample:
http://people.apache.org/~jgallimore/runas-sample.tar.gz which works in
OpenEJB/Tomcat for me.

I needed to add

    <servlet>
        <servlet-name>TestServlet</servlet-name>
        <servlet-class>org.superbiz.web.TestServlet</servlet-class>
        <run-as>
            <role-name>admin</role-name>
        </run-as>
    </servlet>

to my web.xml to get it to work. I guess the @RunAs annotation would work on
the Servlet, but I haven't tried it.

Hope that helps.

Jon

On Thu, Sep 24, 2009 at 4:51 PM, Jonathan Gallimore <
[email protected]> wrote:

> 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