(tomcat) branch 10.1.x updated: Improve handling of get[Pooled]Connection(String,String)

[email protected]
Newsgroups gmane.comp.jakarta.tomcat.devel
Message-ID <178772591044.1255411.17715577084877227564@gitbox3-he-fi.apache.org>
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/10.1.x by this push:
     new 4e335f4441 Improve handling of get[Pooled]Connection(String,String)
4e335f4441 is described below

commit 4e335f4441b3f487474ca46f074f0b517837e46f
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                               | 14 ++++++++++++++
 2 files changed, 26 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 54b6eb33f2..f3236bd5c9 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 d51a2242b5..fc6849ed0c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -180,6 +180,20 @@
       </docs>
     </changelog>
   </subsection>
+  <subsection name="jdbc-pool">
+    <changelog>
+      <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>
 </section>
 
 <section name="Tomcat 10.1.59 (schultz)" rtext="2026-08-20">
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.