This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 8fe274d735 Improve handling of get[Pooled]Connection(String,String)
8fe274d735 is described below

commit 8fe274d735525255b550a808d756ec5de21cb474
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Aug 26 07:30:08 2026 +0100

    Improve handling of get[Pooled]Connection(String,String)
---
 .../org/apache/tomcat/jdbc/pool/DataSourceProxy.java     | 16 ++++++++++++----
 webapps/docs/changelog.xml                               | 10 ++++++++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
index 7079e7b419..487a744cef 100644
--- 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
+++ 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
@@ -23,6 +23,7 @@ import java.sql.SQLFeatureNotSupportedException;
 import java.util.Iterator;
 import java.util.Properties;
 import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.logging.Logger;
 
 import javax.sql.XAConnection;
@@ -43,6 +44,8 @@ import 
org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorDefinition;
 public class DataSourceProxy implements PoolConfiguration {
     private static final Log log = LogFactory.getLog(DataSourceProxy.class);
 
+    private final AtomicBoolean connectionWithoutCredentialsWarningIssued = 
new AtomicBoolean(false);
+
     /**
      * The underlying connection pool.
      */
@@ -120,6 +123,11 @@ public class DataSourceProxy implements PoolConfiguration {
             }
             return pool.getConnection(username,password);
         } else {
+            if (connectionWithoutCredentialsWarningIssued.compareAndSet(false, 
true)) {
+                log.warn(String.format(
+                        "alternateUsernameAllowed is set to false so the 
provided user name [%s] and associated " +
+                        "password have been ignored", username));
+            }
             return getConnection();
         }
     }
@@ -238,15 +246,15 @@ public class DataSourceProxy implements PoolConfiguration 
{
 
     /**
      * Get a database connection.
-     * {@link javax.sql.DataSource#getConnection()}
-     * @param username unused
-     * @param password unused
+     * {@link javax.sql.DataSource#getConnection(String,String)}
+     * @param username The user name
+     * @param password The password
      * @return the connection
      * @throws SQLException Connection error
      */
     public javax.sql.PooledConnection getPooledConnection(String username,
             String password) throws SQLException {
-        return (javax.sql.PooledConnection) getConnection();
+        return (javax.sql.PooledConnection) getConnection(username, password);
     }
 
     /**
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 5586d49128..dbe88985a7 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -430,6 +430,16 @@
   <subsection name="jdbc-pool">
     <changelog>
       <!-- Entries for backport and removal before 12.0.0-M1 below this line 
-->
+      <fix>
+        <code>DataSourceProxy.getPooledConnection(String,String)</code> now
+        delegates to <code>getConnection(String,String)</code> rather than
+        <code>getConnection()</code>. (markt)
+      </fix>
+      <add>
+        Log a warning if an attempt is made to obtain a connection with
+        credentials when <code>alternateUsernameAllowed</code> is set to
+        <code>false</code>. (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Other">


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to