Estoy ejecutando Glassfish 4 y Jersey como implementación de Jax-RS. He asegurado mi EJB así:
@Stateless
@DeclareRoles({"Authentication_Reader"})
@RolesAllowed({"Authentication_Reader"})
public class AuthenticationServiceBean {
public void foo() {
...
}
}
He creado una entrada de mapeo de rol de seguridad en Glassfish-Web.xml, y también he creado una declaración de rol de seguridad en Web.xml.
Los siguientes trabajan desde un servlet:
@WebServlet(name = "TestServlet", urlPatterns = {"/test.do"})
@RunAs("Authentication_Reader")
public class TestServlet extends HttpServlet {
@Inject
private AuthenticationServiceBean authenticationService;
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
authenticationService.foo();
.. etc ...
}
}
Pero si lo hago desde un recurso Jax-RS, como este:
@RequestScoped
@RunAs("Authentication_Reader")
@Path("test")
public class TestResource {
@Inject
private AuthenticationServiceBean authenticationServiceBean;
@GET
public String test() {
int x = 123; // This code executes fine
authenticationServiceBean.foo(); // This gets an AccessLocalException
return "I never returned this";
}
}
El registro del servidor de peces de vidrio básicamente dice: javax.ejb.accesslocalException: Cliente no autorizado para esta invocación
No entiendo por qué esto funciona para un servlet, y no para el recurso del resto. Para mí, esto parece que debería funcionar bien.