title: Wildfly 15 get EJBContext in Singleton from jax rs logged in user
body: <p>I want to get the caller principal in an singleton from the logged in user. the user is authenticating against the rest service with username/password</p>
  
  <p>the security domain is in the jboss-web.xml in the war</p>
  
  <pre><code>&lt;security-domain&gt;application-security&lt;/security-domain&gt;
  </code></pre>
  
  <p>The endpoint in the war is:</p>
  
  <pre><code>@Path("/message/{message}")
  public class MyRessource
  {  
     @EJB
     MySingleton singletonBean;
  
     @GET
     public Response resource(@PathParam("message") String message)
     {        
          singletonBean.printText(message);
          System.out.println("called from: " + ctx.getUserPrincipal().getName());
  }
  </code></pre>
  
  <p>the singleton is in an own project, and is provided as dependency at the war.</p>
  
  <pre><code>@Stateless
  public class MySingletonBean implements MySingleton
  {
  
      @Resource
      EJBContext context;
  
      @Resource
      SessionContext ctx;
  
    public void printText(String text) {
        System.out.println(text + ":: EJBContext: " + context.getCallerPrincipal().getName() + "  SessionContext: " + ctx.getCallerPrincipal().getName());      
    }
  
  }
  </code></pre>
  
  <p>my web.xml:</p>
  
  <pre><code>&lt;web-app&gt;
      &lt;security-role&gt;
          &lt;role-name&gt;Admin&lt;/role-name&gt;
      &lt;/security-role&gt;
  
      &lt;security-constraint&gt;
          &lt;web-resource-collection&gt;
              &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
              &lt;http-method-omission&gt;OPTIONS&lt;/http-method-omission&gt;
          &lt;/web-resource-collection&gt;
          &lt;auth-constraint&gt;
              &lt;role-name&gt;Admin&lt;/role-name&gt;
          &lt;/auth-constraint&gt;
      &lt;/security-constraint&gt;
      &lt;login-config&gt;
          &lt;auth-method&gt;BASIC&lt;/auth-method&gt;
      &lt;/login-config&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>standalone-full-ha.xml</p>
  
  <pre><code>&lt;subsystem xmlns="urn:wildfly:elytron:5.0" ...&gt;
     [...]
     &lt;security-domain name="application-security" default-realm="application-properties" permission-mapper="default-permission-mapper"&gt;
        &lt;realm name="application-properties"/&gt;
     &lt;/security-domain&gt;
     [...]
  &lt;/subsystem&gt;
     [...]
  
  &lt;http-authentication-factory name="application-security-http" security-domain="application-security" http-server-mechanism-factory="global"&gt;
     &lt;mechanism-configuration&gt;
        &lt;mechanism mechanism-name="BASIC"/&gt;
     &lt;/mechanism-configuration&gt;
  &lt;/http-authentication-factory&gt;
  [...]
  
  &lt;security-domains&gt;
     &lt;security-domain name="application-security" default-realm="application-properties" permission-mapper="default-permission-mapper"&gt;
        &lt;realm name="application-properties"/&gt;
      &lt;/security-domain&gt;
     [...]
  &lt;/security-domains&gt;
  [...]
  
  &lt;subsystem xmlns="urn:jboss:domain:security:2.0"&gt;
     &lt;security-domains&gt;
        &lt;security-domain name="application-security"&gt;
           &lt;authentication&gt;
              &lt;login-module code="UsersRoles" flag="required"&gt;
                 &lt;module-option name="usersProperties" value="file://${jboss.server.config.dir}/context-users.properties"/&gt;
                  &lt;module-option name="rolesProperties" value="file://${jboss.server.config.dir}/context-roles.properties"/&gt;
               &lt;/login-module&gt;
            &lt;/authentication&gt;
       &lt;/security-domain&gt;
       [...]
  &lt;/subsystem&gt;
  [...]
  
  &lt;subsystem xmlns="urn:boss:domain:undertow"...&gt;
      &lt;application-security-domains&gt;
          &lt;application-security-domain name="application-security" http-authentication-factory="application-security-http"/&gt;
      &lt;/application-security-domains&gt;
      [...]
  &lt;/subsystem&gt;
  </code></pre>
  
  <p>But i always get anonymous as principals. </p>
  
  <p>What did i do wrong?</p>