title: How do I configure a SQL Server datasource in JBoss to connect using a specific Active Directory user?
body: <p>JBoss runs as Active Directory user <code>ABC\appuser</code>.  I want to connect to a MS SQL Server 8.0 database as AD user <code>ABC\dbuser</code>.  Using parameter <code>integratedSecurity=true</code>, unless I specify <code>user=ABC\dbuser;password=dbpass</code> on the connection url, the system will try to connect as the service AD user, <code>ABC\appuser</code>.</p>
  
  <p>Per <a href="https://stackoverflow.com/questions/24702084/how-to-configure-a-jdbc-connection-to-use-a-different-ad-user-than-the-current-u/24702718">this question</a>, I have confirmed that by using the following url, I can connect to the database as <code>ABC\dbuser</code> when running the application as <code>ABC\appuser</code>:</p>
  
  <pre><code>jdbc:sqlserver://MYHOSTNAME:1433;DatabaseName=MyDatabaseName;integratedSecurity=true;user=ABC\dbuser;password=dbpass
  </code></pre>
  
  <p>Unfortunately, when I set the url for the datasource in the JBoss configuration xml ( <code>JBoss\jboss-eap-6.1.0\standalone\configuration\standalone.xml</code> ) as follows:</p>
  
  <pre><code>&lt;datasource jndi-name="java:jboss/datasources/MyDatabaseName" pool-name="MyPoolName" enabled="true" use-java-context="true"&gt;
    &lt;connection-url&gt;jdbc:sqlserver://MYHOSTNAME:1433;DatabaseName=MyDatabaseName;integratedSecurity=true;user=ABC\dbuser;password=dbpass&lt;/connection-url&gt;
    &lt;driver&gt;sqlserver&lt;/driver&gt;
    &lt;pool&gt;
      &lt;min-pool-size&gt;1&lt;/min-pool-size&gt;
      &lt;max-pool-size&gt;10&lt;/max-pool-size&gt;
      &lt;prefill&gt;true&lt;/prefill&gt;
    &lt;/pool&gt;
    &lt;security&gt;
      &lt;user-name&gt;&lt;/user-name&gt;
      &lt;password&gt;&lt;/password&gt;
    &lt;/security&gt;
  &lt;/datasource&gt;
  </code></pre>
  
  <p>I am unable to create the pool resource with this warning:</p>
  
  <pre><code>WARN  
  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (JCA PoolFiller) 
  IJ000610: Unable to fill pool: 
  javax.resource.ResourceException: Could not create connection
  </code></pre>
  
  <p>Setting values for <code>user-name</code> and <code>password</code> XML entries creates a similar failure warning.</p>
  
  <p>My current workaround options seem to be any of:</p>
  
  <ol>
  <li>extending whichever class JBoss is using to create this datasource, replacing it with a custom class that applies the <code>connection-url</code> value as expected or</li>
  <li>changing JBoss to run as <code>ABC\dbuser</code> or </li>
  <li>giving the JBoss service user <code>ABC\appuser</code> database access by either giving it direct access or adding it to an AD Group with access.</li>
  </ol>
  
  <p>None of these workarounds is preferable; there must be a more elegant, accepted solution.  How can I resolve this?</p>