Wildfly Login With Username And Role
<p>For an integration test EAR I need my Wildfly to be able to log in different users with a specific role.</p>

<ul>
<li><code>org.jboss.security.auth.spi.SimpleServerLoginModule</code> doesn't allow me to specify a role</li>
<li><code>org.jboss.security.auth.spi.IdentityLoginModule</code> doesn't allow different users</li>
</ul>

<p>So evidently I need to use something different. I tried to use a temporary database like this:</p>



<pre><code>&lt;login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule"
        flag="required"&gt;
    &lt;module-option name="dsJndiName" value="java:/AcmeDS" /&gt;
    &lt;module-option name="principalsQuery" value="SELECT ?" /&gt;
    &lt;module-option name="rolesQuery" value="SELECT 'my_role', 'Roles'" /&gt;
    &lt;module-option name="password-stacking" value="useFirstPass" /&gt;
&lt;/login-module&gt;
</code></pre>

<p>...aaand:</p>



<pre><code>&lt;datasources&gt;
    &lt;datasource jndi-name="java:/AcmeDS" pool-name="AcmeDS" enabled="true"&gt;
    &lt;connection-url&gt;jdbc:h2:mem:test;DB_CLOSE_DELAY=-1&lt;/connection-url&gt;
    &lt;driver&gt;h2&lt;/driver&gt;
        &lt;pool&gt;
            &lt;min-pool-size&gt;10&lt;/min-pool-size&gt;
            &lt;max-pool-size&gt;20&lt;/max-pool-size&gt;
            &lt;prefill&gt;true&lt;/prefill&gt;
        &lt;/pool&gt;
        &lt;security&gt;
            &lt;user-name&gt;sa&lt;/user-name&gt;
            &lt;password&gt;sa&lt;/password&gt;
        &lt;/security&gt;
    &lt;/datasource&gt;
    &lt;drivers&gt;
        &lt;driver name="h2" module="com.h2database.h2"&gt;
            &lt;xa-datasource-class&gt;org.h2.jdbcx.JdbcDataSource&lt;/xa-datasource-class&gt;
        &lt;/driver&gt;
    &lt;/drivers&gt;
&lt;/datasources&gt;
</code></pre>

<p>As suggested in the <a href="https://docs.jboss.org/author/display/WFLY8/DataSource+configuration" rel="nofollow">JBoss tutorial</a>. Still I get the following exception for the clients:</p>

<pre><code>java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: the server presented no authentication mechanisms
at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:92)
at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:77)
at org.jboss.ejb.client.remoting.RemotingConnectionManager.getConnection(RemotingConnectionManager.java:51)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:155)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:115)
</code></pre>

<p>5 minutes later I got (I'm not aware of any changes): <code>all available authentication mechanisms failed</code></p>

<p>(It worked right until the point where I needed a role, so I guess the setup for the client side is okay.)</p>

<p>What did I do I wrong? How can I get the Wildfly to at least show exceptions or something so I can debug the problem? Is there a better way to get the Wilfly to acknowledge different users with a specific role?</p>