2

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?

user3151902
  • 3,154
  • 1
  • 19
  • 32

1 Answers1

1

Try this one:

@Resource
EJBContext context;

...

context.getCallerPrincipal()
markus
  • 602
  • 4
  • 13