I have a simple REST webservice that uses basic authentication.
@Path("/ws")
@Stateless
public class MyWebservice {
@EJB
private MyEJB myEjb;
@GET
@Path("/get")
@Produces(MediaType.APPLICATION_JSON)
public MyObject getObject() {
return myEjb.getObject();
}
}
The EJB is also really simple:
@Stateless
public class MyEJB {
@Resource(lookup = "java:comp/EJBContext")
private SessionContext sessionContext;
@PermitAll
public MyObject getObject() {
return new MyObject();
}
}
However, when I debug, the principal in the EJB in the sessionContext
is always "anonymous", no matter what user I use to authenticate against the WS.
How can I set the EJB principal to the same as the one that is authenticated against the webservice?