Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance the JDBC Driver Manager to validate all driver supported properies (JDBC-driver, #1825) #1827

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ private Connection doConnect(String driverClass, String url, String jndiNameUrl,
try {
Driver driver = DriverManager.getDriver(url);
if (driver != null) {
removeUnsupportedConnectionProperties(driver, url, connectionProperties);
return driver.connect(url, connectionProperties);
}
} catch (SQLException e1) {
Expand All @@ -292,6 +293,7 @@ private Connection doConnect(String driverClass, String url, String jndiNameUrl,
}

try {
removeUnsupportedConnectionProperties(DriverManager.getDriver(url), url, connectionProperties);
return DriverManager.getConnection(url, connectionProperties);
} catch (SQLException e) {
try {
Expand All @@ -301,7 +303,9 @@ private Connection doConnect(String driverClass, String url, String jndiNameUrl,

Class dc = dl.loadClass(driverClass);
if (dc != null) {
Connection conn = ((Driver) dc.newInstance()).connect(url, connectionProperties);
Driver driver = (Driver) dc.newInstance();
removeUnsupportedConnectionProperties(driver, url, connectionProperties);
Connection conn = driver.connect(url, connectionProperties);
if (conn != null) {
return conn;
}
Expand All @@ -313,6 +317,31 @@ private Connection doConnect(String driverClass, String url, String jndiNameUrl,
}
}

/*
* Remove unsupported properties from the connection properties
* based on the driver property information set
speckyspooky marked this conversation as resolved.
Show resolved Hide resolved
*/
private void removeUnsupportedConnectionProperties(Driver driver, String url, Properties connectionProperties) {
try {
DriverPropertyInfo[] supportedProperties = driver.getPropertyInfo(url, connectionProperties);
if (supportedProperties != null && connectionProperties != null) {
connectionProperties.keySet().removeIf(property -> {
String key = property.toString();
if ("password".equalsIgnoreCase(key) || "user".equalsIgnoreCase(key)) {
return false;
}
for (DriverPropertyInfo supportedProperty : supportedProperties) {
if (supportedProperty.name.equalsIgnoreCase(key)) {
return false;
}
}
return true;
});
}
} catch (SQLException e) {
// do nothing, standard handling
}
}
/**
*
* @param message
Expand Down
Loading