Sto correndo Glassfish 4 e Jersey come implementazione di JAX-RS. Ho assicurato il mio EJB in questo modo:
@Stateless
@DeclareRoles({"Authentication_Reader"})
@RolesAllowed({"Authentication_Reader"})
public class AuthenticationServiceBean {
public void foo() {
...
}
}
Ho creato una voce di mappatura della sicurezza in Glassfish-web.xml e ho anche creato una dichiarazione di ruolo di sicurezza in web.xml.
Le seguenti opera da 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 ...
}
}
Ma se lo faccio da una risorsa Jax-RS, come questa:
@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";
}
}
Il registro del server Glassfish in pratica dice: Javax.ejb.AccessLocalexception: client non autorizzato per questa invocazione
Non capisco perché funzioni per un servlet e non per la risorsa REST. Per me, questo sembra che dovrebbe funzionare bene.