Bug 1103684 - Unable to share Identity Security Domain across datasources
Summary: Unable to share Identity Security Domain across datasources
Alias: None
Product: JBoss Enterprise Application Platform 6
Classification: JBoss
Component: Security, Documentation
Version: 6.3.0
Hardware: Unspecified
OS: Unspecified
Target Milestone: post-GA
: EAP 6.4.2
Assignee: Andrea Hoffer
QA Contact: Josef Cacek
Russell Dickenson
Whiteboard: ShouldBeFixed
Depends On:
TreeView+ depends on / blocked
Reported: 2014-06-02 11:12 UTC by Darran Lofthouse
Modified: 2019-08-15 03:51 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: Known Issue
Doc Text:
In this release of JBoss EAP 6, the error `javax.resource.ResourceException: No matching credentials in Subject!` is presented when multiple datasources are defined backed by the same security domain. The workaround is to disable caching on the security domain if it must be shared among datasources. Otherwise, a separate security domain should be used for each datasource.
Clone Of:
Last Closed: 2015-10-20 12:45:59 UTC
Type: Bug
dmichael: needinfo-

Attachments (Terms of Use)
test-service.war (6.40 KB, application/x-webarchive)
2014-06-02 16:24 UTC, John Mazzitelli
no flags Details

System ID Priority Status Summary Last Updated
Red Hat Bugzilla 1102332 None None None Never

Internal Links: 1102332

Description Darran Lofthouse 2014-06-02 11:12:50 UTC
Description of problem:

Where multiple datasources are defined backed by the same security domain the following error is seen: -

Caused by: javax.resource.ResourceException: No matching credentials in Subject!
     at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnectionFactory.getConnectionProperties(BaseWrapperManagedConnectionFactory.java:965)

Debugging the connection attempt I see the Subject being compared was as a result of calling the security domain, i.e. not a Subject pulled off the AccessControlContext.

The comparison fails because the PasswordCredential IronJacamar finds contains a reference to the ManagedConnectionFactory.

What I believe is something has got out of sync when it comes to the intended use of security domains with datasources and a previous call has been cached hence a datasource now receiving a Principal intended for another datasource.

See the following for the underlying issue: -

Comment 1 John Mazzitelli 2014-06-02 16:24:04 UTC
Created attachment 901502 [details]

I am attaching a test war that replicates the problem. It is a simple WAR with a single servlet .java class file. The .java source is in the WAR next to the .class files so you can see the code and debug it.

Here's a quick summary of the replication procedures - I will provide more details after this summary:


1) Add a single security-domain for the the H2 database's "sa" credentials.
2) Add two datasources - one <datasource>, one <xa-datasource> that share the above security domain. Point the datasources to the H2 database that comes with the EAP build.
3) Copy the attached test-service.war to the EAP's standalone/deployments directory.
4) Run bin/standalone.sh
5) Point your browser to http://localhost:8080/test-service/BugTestServlet

At this point, you should see the exceptions in the server log. If you don't see the error, make another browser request until you see the exception. I've had to make at most two browser requests in order to see the error happen. It is easy to replicate.


To run, you need to add these to your standalone.xml first:

1) Add a single security-domain that our test datasources will share - the password you see here is the obscured "sa" password of the H2 test database that comes with the default EAP build:

    <security-domain name="BugTest-policy" cache-type="default">
            <login-module code="SecureIdentity" flag="required">
                <module-option name="username" value="sa"/>
                <module-option name="password" value="9fdd42c2a7390d3"/>

2) Add two new datasources that share the above security domain - one is a datasource, the other a XA datasource - YOU MUST HAVE BOTH TYPES. This bug does NOT show itself if you use two <datasource> entries - I think they must be different types of datasources for the bug to show up!!!:

    <datasource jndi-name="java:jboss/datasources/BugTestDS1" pool-name="BugTestDS1" enabled="true" use-java-context="true">

    <xa-datasource jndi-name="java:jboss/datasources/BugTestDS2" pool-name="BugTestDS2" enabled="true" use-java-context="true">
        <xa-datasource-property name="URL">

Now, copy the attached test-service.war to an EAP 6.3 standalone/deployments directory, and run the server normally via standalone.sh.

The servlet will run two queries - one with each datasource - during its init() method during startup - this was done to show that running the queries over both datasources *sequentially* works fine.

But then, make a request to the servlet so its doGet runs those same two queries concurrently on separate threads. You do this by pointing your browser to http://localhost:8080/test-service/BugTestServlet - if the failure doesn't show up on the first request, make another request. I have consistently reproduced this bug on either the first or second browser request I've made - it is very easy to make the bug occur.

Comment 3 Darran Lofthouse 2014-11-20 13:56:39 UTC
I think this one needs re-categorising to be a documentation issue only.

Essentially it is an aspect of the JCA specification that makes it mandatory that the PasswordCredential that is obtained is then associated with the ManagedConnectionFactory it is used with.

So if a security domain is to be used with multiple datasources then no caching should be enabled for that domain, this means that each time the PasswordCredential is obtained from the security domain it will be a new instance and the association / checking of the existing ManagedConnectionFactory will not cause any errors.

However if caching of the security domain call is desirable then one security domain will be required per datasource, this way the obtained PasswordCredential can be cached but at there is a 1:1 mapping of domain to datasource there will not be a conflict when it comes to the ManagedConnectionFactory association.

Comment 14 Josef Cacek 2015-09-15 11:14:18 UTC
Verified in A&C guide revision 6.4.0-37

Note You need to log in before you can comment on or make changes to this bug.