swaldman / c3p0

a mature, highly concurrent JDBC Connection pooling library, with support for caching and reuse of PreparedStatements.
http://www.mchange.com/projects/c3p0
Other
1.28k stars 338 forks source link

password in null when using com.microsoft.sqlserver.jdbc.SQLServerDriver #159

Closed sbaeumlisberger closed 6 months ago

sbaeumlisberger commented 2 years ago

When using the user and password properties with com.microsoft.sqlserver.jdbc.SQLServerDriver the password passed to the SQLServerDataSource connect method is null.

The cause of this issue is that in the C3P0ImplUtils class the password is retrieved form the nested data source, but the getter for the password in the SQLServerDataSource is not public. Therfore the readMethod is null and the password is not retrieved.

We are using osgi and the datasource config looks like that:

osgi.jdbc.driver.name=Microsoft JDBC Driver for SQL Server
osgi.jdbc.driver.class=com.microsoft.sqlserver.jdbc.SQLServerDriver

url=jdbc:sqlserver://localhost:1433;databaseName=devdb;
user=dbuser
password=dbpass

dataSourceName=ds

pool=c3p0
xa=false

jdbc.c3p0.dataSourceName=ds

Here I have attached a little standalone maven project to reproduce the issue: project.zip

If you need more information, let me know.

swaldman commented 6 months ago

I think that this addresses the issue! If we can read the user but only a null password, we test to see if that authentication works, if not we revert to the inner DataSource's default authentication (i.e. DataSource.getConnection() with no arguments.)

https://github.com/swaldman/c3p0/commit/ecbe0fb2be306d30d44ac2686244ac830c6dd6f4

Thanks!