From b72dba6b033a0da3c6bd8db248b848313dfe8fe9 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Thu, 7 Sep 2017 16:07:59 -0400 Subject: [PATCH] GUACAMOLE-363: Update so that any of the available TDS-compatible drivers can be used. --- ...SQLServerAuthenticationProviderModule.java | 15 ++++--- .../auth/sqlserver/SQLServerEnvironment.java | 39 +++++++++++++++++-- .../SQLServerGuacamoleProperties.java | 6 +-- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerAuthenticationProviderModule.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerAuthenticationProviderModule.java index d936f140d..22c543403 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerAuthenticationProviderModule.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerAuthenticationProviderModule.java @@ -44,8 +44,8 @@ public class SQLServerAuthenticationProviderModule implements Module { /** * Whether or not to use JTDS Driver */ - private Boolean useJTDSDriver = false; - + private String sqlServerDriver; + /** * Creates a new SQLServer authentication provider module that configures * driver and MyBatis properties using the given environment. @@ -75,8 +75,8 @@ public class SQLServerAuthenticationProviderModule implements Module { // Use UTF-8 in database driverProperties.setProperty("characterEncoding", "UTF-8"); - // Capture whether or not to use the JTDS driver. - this.useJTDSDriver = environment.getSQLServerJTDSDriver(); + // Capture which driver to use for the connection. + this.sqlServerDriver = environment.getSQLServerDriver(); } @@ -84,8 +84,13 @@ public class SQLServerAuthenticationProviderModule implements Module { public void configure(Binder binder) { // 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); + 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 JdbcHelper.SQL_Server_2005_MS_Driver.configure(binder); diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerEnvironment.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerEnvironment.java index 4d24dd36b..2110b0c7d 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerEnvironment.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerEnvironment.java @@ -96,6 +96,30 @@ public class SQLServerEnvironment extends JDBCEnvironment { */ 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 * 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 @@ -314,10 +347,10 @@ public class SQLServerEnvironment extends JDBCEnvironment { * If an error occurs while retrieving the property value, or if the * value was not set, as this property is required. */ - public Boolean getSQLServerJTDSDriver() throws GuacamoleException { + public String getSQLServerDriver() throws GuacamoleException { return getProperty( - SQLServerGuacamoleProperties.SQLSERVER_JTDS_DRIVER, - false + SQLServerGuacamoleProperties.SQLSERVER_DRIVER, + SQLSERVER_DRIVER_MS_2005 ); } diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerGuacamoleProperties.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerGuacamoleProperties.java index d04d9a13c..9d9b3864b 100644 --- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerGuacamoleProperties.java +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerGuacamoleProperties.java @@ -200,11 +200,11 @@ public class SQLServerGuacamoleProperties { /** * Whether or not to use the JTDS driver for SQL Server connections. */ - public static final BooleanGuacamoleProperty - SQLSERVER_JTDS_DRIVER = new BooleanGuacamoleProperty() { + public static final StringGuacamoleProperty + SQLSERVER_DRIVER = new StringGuacamoleProperty() { @Override - public String getName() { return "sqlserver-use-jtds-driver"; } + public String getName() { return "sqlserver-driver"; } };