title: Propagate user principal from REST to EJB layer
body: <p>I am starting an application that uses a REST api which makes calls to an EJB layer on JBoss Wildfly (RestEasy).</p>
  
  <p>The REST services are inside a war which then calls the ejb layer.
  I know how to achieve BASIC or any custom form of authenthication on REST with an RestEasy Interceptor that checks Headers etc.
  Basically like described here: <a href="http://howtodoinjava.com/2013/06/26/jax-rs-resteasy-basic-authentication-and-authorization-tutorial/" rel="noreferrer">http://howtodoinjava.com/2013/06/26/jax-rs-resteasy-basic-authentication-and-authorization-tutorial/</a></p>
  
  <p>The problem now is - this is just a check on the REST facade. Inside the EJB layer I don't know the user that authenticated against the REST service. </p>
  
  <p>To clear this - when using RMI and Remote EJB calls with authentication, the user name is stored in Session Context:</p>
  
  <pre><code>@Stateless
  public class LoginService {
  @Resource
  private SessionContext sessionContext;
  
    public String getCurrentUser() {
      Principal principal = sessionContext.getCallerPrincipal();
      return principal.getName(); //I need this to be the username from REST auth
      //Currently it's anonymous
    }
  }
  </code></pre>
  
  <p>Is there a way to propagate the username in some standard way? E.g. putting a custom principal to SessionContext?</p>