3 Replies Latest reply on Sep 3, 2014 6:36 AM by Antlia Antlia

    Anonymous principal when invoking EJB from a thread inside a servlet

    Antlia Antlia Newbie



      I've created some threads inside a servlet for loading content asynchronously because it requires a while to load.


      In these threads there are some calls to EJB methods, some of them are associated with an interceptor which verifies the user contained in SessionContext.


      I noticed that if these methods are invoked by the servlet's main thread, method getCallerPrincipal returns the right username of the user who logged in in servlet part, but if these methods are invoked by another thread manually created and started inside the same servlet, getCallerPrincipal always returns 'anonymous' causing security exceptions and issues on methods annotated with @RolesAllowed.


      For log in I'm using HttpServletRequest.login method.


      Does anyone have the same problem? How to manage this?