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

Attachment: run_as.war
Description: application/webarchive

Reply via email to