GUACAMOLE-363: Update so that any of the available TDS-compatible drivers can be used.

This commit is contained in:
Nick Couchman
2017-09-07 16:07:59 -04:00
parent d6d7c3768f
commit b72dba6b03
3 changed files with 49 additions and 11 deletions

View File

@@ -44,8 +44,8 @@ public class SQLServerAuthenticationProviderModule implements Module {
/** /**
* Whether or not to use JTDS Driver * Whether or not to use JTDS Driver
*/ */
private Boolean useJTDSDriver = false; private String sqlServerDriver;
/** /**
* Creates a new SQLServer authentication provider module that configures * Creates a new SQLServer authentication provider module that configures
* driver and MyBatis properties using the given environment. * driver and MyBatis properties using the given environment.
@@ -75,8 +75,8 @@ public class SQLServerAuthenticationProviderModule implements Module {
// Use UTF-8 in database // Use UTF-8 in database
driverProperties.setProperty("characterEncoding", "UTF-8"); driverProperties.setProperty("characterEncoding", "UTF-8");
// Capture whether or not to use the JTDS driver. // Capture which driver to use for the connection.
this.useJTDSDriver = environment.getSQLServerJTDSDriver(); this.sqlServerDriver = environment.getSQLServerDriver();
} }
@@ -84,8 +84,13 @@ public class SQLServerAuthenticationProviderModule implements Module {
public void configure(Binder binder) { public void configure(Binder binder) {
// Bind SQLServer-specific properties // Bind SQLServer-specific properties
if (this.useJTDSDriver) // Look at the property to choose the correct driver.
if (sqlServerDriver.equals(SQLServerEnvironment.SQLSERVER_DRIVER_JTDS))
JdbcHelper.SQL_Server_jTDS.configure(binder); JdbcHelper.SQL_Server_jTDS.configure(binder);
else if(sqlServerDriver.equals(SQLServerEnvironment.SQLSERVER_DRIVER_DATADIRECT))
JdbcHelper.SQL_Server_DataDirect.configure(binder);
else if(sqlServerDriver.equals(SQLServerEnvironment.SQLSERVER_DRIVER_MS))
JdbcHelper.SQL_Server_MS_Driver.configure(binder);
else else
JdbcHelper.SQL_Server_2005_MS_Driver.configure(binder); JdbcHelper.SQL_Server_2005_MS_Driver.configure(binder);

View File

@@ -96,6 +96,30 @@ public class SQLServerEnvironment extends JDBCEnvironment {
*/ */
private int DEFAULT_MAX_GROUP_CONNECTIONS = 0; private int DEFAULT_MAX_GROUP_CONNECTIONS = 0;
/**
* The value for the sqlserver-driver property that triggers the use of
* the open source JTDS driver.
*/
public final static String SQLSERVER_DRIVER_JTDS = "jtds";
/**
* The value for the sqlserver-driver property that triggers the use of
* the DataDirect JDBC driver.
*/
public final static String SQLSERVER_DRIVER_DATADIRECT = "datadirect";
/**
* The value for the sqlserver-driver property that triggers the use of
* the older Microsoft JDBC driver.
*/
public final static String SQLSERVER_DRIVER_MS = "microsoft";
/**
* The value for the sqlserver-driver property that triggers the use of
* the Microsoft JDBC driver. This is the default.
*/
public final static String SQLSERVER_DRIVER_MS_2005 = "microsoft2005";
/** /**
* Constructs a new SQLServerEnvironment, providing access to SQLServer-specific * Constructs a new SQLServerEnvironment, providing access to SQLServer-specific
* configuration options. * configuration options.
@@ -169,6 +193,15 @@ public class SQLServerEnvironment extends JDBCEnvironment {
} }
// Check driver property is one of the acceptable values.
String driver = getProperty(SQLServerGuacamoleProperties.SQLSERVER_DRIVER);
if (!(driver.equals(SQLSERVER_DRIVER_JTDS) ||
driver.equals(SQLSERVER_DRIVER_DATADIRECT) ||
driver.equals(SQLSERVER_DRIVER_MS) ||
driver.equals(SQLSERVER_DRIVER_MS_2005)))
logger.warn("{} property has been set to an invalid value. The default Microsoft 2005 driver will be used.",
SQLServerGuacamoleProperties.SQLSERVER_DRIVER.getName());
} }
@Override @Override
@@ -314,10 +347,10 @@ public class SQLServerEnvironment extends JDBCEnvironment {
* If an error occurs while retrieving the property value, or if the * If an error occurs while retrieving the property value, or if the
* value was not set, as this property is required. * value was not set, as this property is required.
*/ */
public Boolean getSQLServerJTDSDriver() throws GuacamoleException { public String getSQLServerDriver() throws GuacamoleException {
return getProperty( return getProperty(
SQLServerGuacamoleProperties.SQLSERVER_JTDS_DRIVER, SQLServerGuacamoleProperties.SQLSERVER_DRIVER,
false SQLSERVER_DRIVER_MS_2005
); );
} }

View File

@@ -200,11 +200,11 @@ public class SQLServerGuacamoleProperties {
/** /**
* Whether or not to use the JTDS driver for SQL Server connections. * Whether or not to use the JTDS driver for SQL Server connections.
*/ */
public static final BooleanGuacamoleProperty public static final StringGuacamoleProperty
SQLSERVER_JTDS_DRIVER = new BooleanGuacamoleProperty() { SQLSERVER_DRIVER = new StringGuacamoleProperty() {
@Override @Override
public String getName() { return "sqlserver-use-jtds-driver"; } public String getName() { return "sqlserver-driver"; }
}; };