Using Multiple login module in JBoss
<p>I am new to authentication and security area and I am trying to extend the authentication mechanism of my application, which currently provides traditional user name/password authentication, to provide user to authenticate via LDAP Server. </p>

<p>In the current implementation, the application uses <em>j_security_check</em> thread from Server API to authenticate the user. 
The <em>standalone.xml</em> file of Jboss has a login module pointing to a <em>myLoginModuleClass</em> class which extends the <em>jboss.security.auth.spi.UsernamePasswordLoginModule</em>.</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;security-domain name="db-domain"&gt;
  &lt;authentication&gt;
    &lt;login-module code="myLoginModuleClass" flag="required" module="packageForClass"&gt;
      &lt;module-option name="hashAlgorithm" value="SHA-256" /&gt;
      &lt;module-option name="hashEncoding" value="base64" /&gt;
      &lt;module-option name="password-stacking" value="useFirstPass" /&gt;
    &lt;/login-module&gt;
  &lt;/authentication&gt;
&lt;/security-domain&gt;</code></pre>
</div>
</div>
</p>

<p>I have added another login-module called LDAP Login module in a separate security.</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;security-domain name="ldap-domain"&gt;
  &lt;authentication&gt;
    &lt;login-module code="LDAPLoginModule" flag="required" module="LDAPModulePackage"&gt;
      &lt;module-option name="java.naming.factory.initial" value="com.sun.jndi.ldap.LdapCtxFactory" /&gt;
      &lt;module-option name="java.naming.security.authentication" value="simple" /&gt;
      &lt;module-option name="bindCredential" value="secret" /&gt;
      &lt;module-option name="password-stacking" value="useFirstPass" /&gt;
    &lt;/login-module&gt;
  &lt;/authentication&gt;
&lt;/security-domain&gt;</code></pre>
</div>
</div>
</p>

<p>The issue I am currently facing is following: the <em>jboss-web.xml</em> and the project's <em>web.xml</em> both points to existing security domain: db-domain. And I can only specify one security domain there. 
Question: How can I programmatically tell jboss to point to a particular login class based on user selection, meaning if user choose to go have ldap auth, the LDAPLoginModule class is called? Or is there any other better way to have a mix mode authentication?</p>

<p>Thank in advance</p>