title: How to setup an application level SAM in WildFly
body: <p>I previously had some code working on Glassfish, but I want to port it to WildFly.</p>
  
  <p>However, I cannot seem get the module to be invoked by WildFly.  The <code>ServletContextListener</code> initializes the module as follows</p>
  
  <pre>
  AuthConfigFactory.getFactory()
              .registerConfigProvider(new OpenIdConnectModuleConfigProvider(options, null),
               "HttpServlet", getAppContext(sce), null);
  </pre>
  
  <p><code>"HttpServlet"</code> is not Glassfish specific and appears to be referenced in <a href="https://github.com/wildfly/wildfly/blob/master/undertow/src/main/java/org/wildfly/extension/undertow/security/jaspi/JASPIAuthenticationMechanism.java?source=cc" rel="nofollow">https://github.com/wildfly/wildfly/blob/master/undertow/src/main/java/org/wildfly/extension/undertow/security/jaspi/JASPIAuthenticationMechanism.java?source=cc</a> </p>
  
  <p>Glassfish does not require a <code>&lt;logon-config&gt;</code> block on the <code>web.xml</code> and putting any variant in WildFly does not work (as expected)</p>
  
  <p>The other place I am suspecting is how I calculate the application context identifier.  For Glassfish I had</p>
  
  <pre><code>private String getAppContext(final ServletContextEvent sce) {
  
      return sce.getServletContext()
          .getVirtualServerName() + " "
              + sce.getServletContext()
                  .getContextPath();
  }
  </code></pre>
  
  <p>Could it be different in WildFly?  Though I saw the similar code in <a href="https://github.com/rdebusscher/secSpikeWeb/blob/master/src/main/java/org/omnifaces/security/jaspic/core/Jaspic.java#L300" rel="nofollow">https://github.com/rdebusscher/secSpikeWeb/blob/master/src/main/java/org/omnifaces/security/jaspic/core/Jaspic.java#L300</a> as well</p>
  
  <p>I have also tried adding to <code>standalone.xml</code> this block</p>
  
  <pre><code>&lt;security-domain name="jaspi" cache-type="default"&gt;
    &lt;authentication-jaspi&gt;
      &lt;login-module-stack name="dummy"&gt;
        &lt;login-module code="Dummy" flag="optional"/&gt;
      &lt;/login-module-stack&gt;
      &lt;auth-module code="org.wildfly.extension.undertow.security.jaspi.modules.HTTPSchemeServerAuthModule" flag="required"/&gt;
    &lt;/authentication-jaspi&gt;
  &lt;/security-domain&gt;
  </code></pre>
  
  <p>And set <code>&lt;default-security-domain value="jaspi"/&gt;</code></p>
  
  <p>However it had no effect and putting a breakpoint in the module didn't show that it gets hit either.</p>
  
  <p>In addition, there I couldn't find a to be a way of doing the following, in WildFly like I would in <code>glassfish-web.xml</code> but that can be another question</p>
  
  <pre><code>&lt;security-role-mapping&gt;
      &lt;role-name&gt;users&lt;/role-name&gt;
      &lt;group-name&gt;https://helloworld&lt;/group-name&gt;
  &lt;/security-role-mapping&gt;
  </code></pre>
  
  <p>The code is pretty big, but the gist of it can be found in </p>
  
  <p><a href="https://github.com/trajano/openid-connect/tree/openid-connect-1.0.1/openid-connect-jaspic-module" rel="nofollow">https://github.com/trajano/openid-connect/tree/openid-connect-1.0.1/openid-connect-jaspic-module</a></p>
  
  <p>and</p>
  
  <p><a href="https://github.com/trajano/openid-connect/tree/openid-connect-1.0.1/openid-connect-jaspic-sample" rel="nofollow">https://github.com/trajano/openid-connect/tree/openid-connect-1.0.1/openid-connect-jaspic-sample</a></p>
  
  <p>Note I am looking for it on the <em>application level</em> and not set a global server JASPI.</p>