title: wildfly: How to use encrypted password for a xa-datasource?
body: <p>I have a wildfly 8.2.0.Final running. I use two oracle datasources, one &lt;datasource&gt; and one &lt;xa-datasource&gt;. I want to have my DB passwords encrypted and managed to do that for the datasource using a security-domain but not for the xa-datasource.
  I haven't found documentation or other postings with a solution for this problem.</p>
  
  <p>Here is what I've done:</p>
  
  <pre><code>        &lt;datasources&gt;
              &lt;datasource jta="false" jndi-name="java:/myproject/jdbc/datasources/jdbc" pool-name="my_JDBC_DS" enabled="true" use-ccm="false"&gt;
                  &lt;connection-url&gt;jdbc:oracle:thin:@localhost:1521:DB&lt;/connection-url&gt;
                  &lt;driver-class&gt;oracle.jdbc.driver.OracleDriver&lt;/driver-class&gt;
                  &lt;driver&gt;oracle&lt;/driver&gt;
                  &lt;pool&gt;
                      &lt;min-pool-size&gt;1&lt;/min-pool-size&gt;
                      &lt;max-pool-size&gt;50&lt;/max-pool-size&gt;
                  &lt;/pool&gt;
                  &lt;security&gt;
                      &lt;security-domain&gt;databaseSecure&lt;/security-domain&gt;
                  &lt;/security&gt;
                  &lt;validation&gt;
                      &lt;check-valid-connection-sql&gt;select 1 from dual&lt;/check-valid-connection-sql&gt;
                      &lt;validate-on-match&gt;true&lt;/validate-on-match&gt;
                      &lt;background-validation&gt;false&lt;/background-validation&gt;
                  &lt;/validation&gt;
              &lt;/datasource&gt;
              &lt;xa-datasource jndi-name="java:/myproject/jdbc/datasources/db_tx" pool-name="MYTXDS" enabled="true" use-ccm="false"&gt;
                  &lt;xa-datasource-property name="URL"&gt;
                      jdbc:oracle:thin:@localhost:1521:DB
                  &lt;/xa-datasource-property&gt;
                  &lt;xa-datasource-property name="User"&gt;
                      scott
                  &lt;/xa-datasource-property&gt;
                  &lt;xa-datasource-property name="Password"&gt;
                      tiger
                  &lt;/xa-datasource-property&gt;
                  &lt;driver&gt;oracle&lt;/driver&gt;
                  &lt;security&gt;
                    &lt;user-name&gt;scott&lt;/user-name&gt;
                      &lt;password&gt;tiger&lt;/password&gt;
                  &lt;/security&gt;
                  &lt;xa-pool&gt;
                      &lt;min-pool-size&gt;1&lt;/min-pool-size&gt;
                      &lt;max-pool-size&gt;50&lt;/max-pool-size&gt;
                      &lt;wrap-xa-resource&gt;false&lt;/wrap-xa-resource&gt;
                  &lt;/xa-pool&gt;
                  &lt;validation&gt;
                      &lt;check-valid-connection-sql&gt;select 1 from dual&lt;/check-valid-connection-sql&gt;
                      &lt;validate-on-match&gt;true&lt;/validate-on-match&gt;
                      &lt;background-validation&gt;false&lt;/background-validation&gt;
                  &lt;/validation&gt;
                  &lt;statement&gt;
                      &lt;prepared-statement-cache-size&gt;32&lt;/prepared-statement-cache-size&gt;
                      &lt;share-prepared-statements&gt;true&lt;/share-prepared-statements&gt;
                  &lt;/statement&gt;
              &lt;/xa-datasource&gt;
              &lt;drivers&gt;
                  &lt;driver name="oracle" module="oracle"&gt;
                      &lt;xa-datasource-class&gt;oracle.jdbc.xa.client.OracleXADataSource&lt;/xa-datasource-class&gt;
                  &lt;/driver&gt;
              &lt;/drivers&gt;
          &lt;/datasources&gt;
  ...
              &lt;security-domain name="databaseSecure" cache-type="default"&gt;
                  &lt;authentication&gt;
                      &lt;login-module code="org.picketbox.datasource.security.SecureIdentityLoginModule" flag="required"&gt;
                          &lt;module-option name="username" value="scott"/&gt;
                          &lt;module-option name="password" value="-170dd0fbd8c13748"/&gt;
                      &lt;/login-module&gt;
                  &lt;/authentication&gt;
              &lt;/security-domain&gt;
  </code></pre>
  
  <p>I've tried removing the xa-datasource-property entries for user and password and referring to the security-domain both nested in the security-tag and on the same level as the properties. Both attempts did not work, with the latter the wildfly exits early because of problems parsing the standalone.xml, with the latter the deployment fails.</p>
  
  <p>To show the most promising attempt, this is how I tried to refer to the security-domain:</p>
  
  <pre><code>&lt;xa-datasource jndi-name="java:/myproject/jdbc/datasources/db_tx" pool-name="MYTXDS" enabled="true" use-ccm="false"&gt;
              &lt;xa-datasource-property name="URL"&gt;
                  jdbc:oracle:thin:@localhost:1521:DB
              &lt;/xa-datasource-property&gt;
              &lt;driver&gt;oracle&lt;/driver&gt;
              &lt;security&gt;
                &lt;security-domain&gt;databaseSecure&lt;/security-domain&gt;
              &lt;/security&gt;
              &lt;xa-pool&gt;
                  &lt;min-pool-size&gt;1&lt;/min-pool-size&gt;
                  &lt;max-pool-size&gt;50&lt;/max-pool-size&gt;
                  &lt;wrap-xa-resource&gt;false&lt;/wrap-xa-resource&gt;
              &lt;/xa-pool&gt;
              &lt;validation&gt;
                  &lt;check-valid-connection-sql&gt;select 1 from dual&lt;/check-valid-connection-sql&gt;
                  &lt;validate-on-match&gt;true&lt;/validate-on-match&gt;
                  &lt;background-validation&gt;false&lt;/background-validation&gt;
              &lt;/validation&gt;
              &lt;statement&gt;
                  &lt;prepared-statement-cache-size&gt;32&lt;/prepared-statement-cache-size&gt;
                  &lt;share-prepared-statements&gt;true&lt;/share-prepared-statements&gt;
              &lt;/statement&gt;
          &lt;/xa-datasource&gt;
  </code></pre>
  
  <p>Doing that the wildfly runs into a <code>javax.resource.ResourceException: No matching credentials in Subject!</code>
  I've debugged into the code and although I'm missing the code for the last few classes in the call stack I see that the Subject actually has the credentials as properties but still the <code>AccessController.doPrivileged</code>call fails, leading to the above mentioned exception.</p>
  
  <p>You see I'm kind of lost, any suggestions?</p>