Index: connector/src/main/org/jboss/resource/connectionmanager/JBossManagedConnectionPool.java =================================================================== --- connector/src/main/org/jboss/resource/connectionmanager/JBossManagedConnectionPool.java (revision 101393) +++ connector/src/main/org/jboss/resource/connectionmanager/JBossManagedConnectionPool.java (working copy) @@ -24,7 +24,6 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Iterator; -import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -337,6 +336,38 @@ } } + private boolean internalTestConnection(Subject subject) + { + boolean result = false; + ConnectionListener cl = null; + try + { + if (getAvailableConnectionCount() > 0) + { + cl = poolingStrategy.getConnection(null, subject, null); + result = true; + } + } + catch (Exception ignored) + { + } + finally + { + if (cl != null) + { + try + { + poolingStrategy.returnConnection(cl, false); + } + catch (ResourceException ire) + { + } + } + } + return result; + } + + /** * Test if a connection can be obtained using default values * @return True if a connection was obtained; otherwise false @@ -347,30 +378,30 @@ { boolean result = false; ConnectionListener cl = null; - try + // first try to get connection with Subject + if (poolingStrategy instanceof BasePool) { - if (getAvailableConnectionCount() > 0) + BasePool basePool = (BasePool)poolingStrategy; + if (basePool.clf instanceof BaseConnectionManager2) { - cl = poolingStrategy.getConnection(null, null, null); - result = true; - } - } - catch (ResourceException re) - { - } - finally - { - if (cl != null) - { - try - { - poolingStrategy.returnConnection(cl, false); + try { + BaseConnectionManager2 baseConnectionMgr = (BaseConnectionManager2)basePool.clf; + Subject subject = baseConnectionMgr.getSubjectFactory().createSubject(baseConnectionMgr.getSecurityDomainJndiName()); + result = internalTestConnection(subject); } - catch (ResourceException ire) + catch ( Exception ignored ) // createSubject could throw security exception, ignore it { + } } } + + // then try to get connection without Subject + if (!result) + { + result = internalTestConnection(null); + } + return result; }