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 f514e4198..ee0584b4f 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 @@ -42,9 +42,9 @@ public class SQLServerAuthenticationProviderModule implements Module { private final Properties driverProperties = new Properties(); /** - * Whether or not to use JTDS Driver + * Which SQL Server driver should be used. */ - private String sqlServerDriver; + private SQLServerDriver sqlServerDriver; /** * Creates a new SQLServer authentication provider module that configures @@ -83,16 +83,25 @@ public class SQLServerAuthenticationProviderModule implements Module { @Override public void configure(Binder binder) { - // Bind SQLServer-specific properties - // 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); + // Bind SQLServer-specific properties with the configured driver. + switch(sqlServerDriver) { + case JTDS: + JdbcHelper.SQL_Server_jTDS.configure(binder); + break; + + case DATA_DIRECT: + JdbcHelper.SQL_Server_DataDirect.configure(binder); + break; + + case MICROSOFT_LEGACY: + JdbcHelper.SQL_Server_MS_Driver.configure(binder); + break; + + case MICROSOFT_2005: + default: + JdbcHelper.SQL_Server_2005_MS_Driver.configure(binder); + + } // Bind MyBatis properties Names.bindProperties(binder, myBatisProperties); diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerDriver.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerDriver.java new file mode 100644 index 000000000..ec01d0668 --- /dev/null +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerDriver.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.guacamole.auth.sqlserver; + +/** + * The possible SQL Server drivers to use when using a TDS-compatible database. + */ +public enum SQLServerDriver { + + /** + * The open source jTDS driver. + */ + JTDS, + + /** + * The Progress DataDirect driver. + */ + DATA_DIRECT, + + /** + * The Microsoft Legacy SQL Server driver. + */ + MICROSOFT_LEGACY, + + /** + * The Microsoft 2005 SQL Server driver. + */ + MICROSOFT_2005; +} diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerDriverProperty.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerDriverProperty.java new file mode 100644 index 000000000..21a62721c --- /dev/null +++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-sqlserver/src/main/java/org/apache/guacamole/auth/sqlserver/SQLServerDriverProperty.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.guacamole.auth.sqlserver; + +import org.apache.guacamole.GuacamoleException; +import org.apache.guacamole.GuacamoleServerException; +import org.apache.guacamole.properties.GuacamoleProperty; + +/** + * A property whose value is a SQLServerDriver. The incoming string values of "jtds", "datadirect", + * "microsoft", and "microsoft2005" into the corresponding SQLServerDriver enum value. Any + * values that are not valid result in a parse error. + */ +public abstract class SQLServerDriverProperty implements GuacamoleProperty { + + @Override + public SQLServerDriver parseValue(String value) throws GuacamoleException { + + // If no value provided, return null. + if (value == null) + return null; + + // jTDS Driver + if (value.equals("jtds")) + return SQLServerDriver.JTDS; + + // Progress DataDirect Driver + if (value.equals("datadirect")) + return SQLServerDriver.DATA_DIRECT; + + // Microsoft Legacy Driver + if (value.equals("microsoft")) + return SQLServerDriver.MICROSOFT_LEGACY; + + // Microsoft 2005 Driver + if (value.equals("microsoft2005")) + return SQLServerDriver.MICROSOFT_2005; + + throw new GuacamoleServerException("SQLServer driver must be one of \"jtds\", \"datadirect\", \"microsoft\", \"microsoft2005\"."); + + } + +} 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 4d3fabab7..efd7ae106 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 @@ -56,69 +56,36 @@ public class SQLServerEnvironment extends JDBCEnvironment { * The default value for the maximum number of connections to be * allowed to the Guacamole server overall. */ - private final int DEFAULT_ABSOLUTE_MAX_CONNECTIONS = 0; + private static final int DEFAULT_ABSOLUTE_MAX_CONNECTIONS = 0; /** * The default value for the default maximum number of connections to be - * allowed per user to any one connection. Note that, as long as the - * legacy "disallow duplicate" and "disallow simultaneous" properties are - * still supported, these cannot be constants, as the legacy properties - * dictate the values that should be used in the absence of the correct - * properties. + * allowed per user to any one connection. */ - private int DEFAULT_MAX_CONNECTIONS_PER_USER = 1; + private static final int DEFAULT_MAX_CONNECTIONS_PER_USER = 1; /** * The default value for the default maximum number of connections to be - * allowed per user to any one connection group. Note that, as long as the - * legacy "disallow duplicate" and "disallow simultaneous" properties are - * still supported, these cannot be constants, as the legacy properties - * dictate the values that should be used in the absence of the correct - * properties. + * allowed per user to any one connection group. */ - private int DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER = 1; + private static final int DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER = 1; /** * The default value for the default maximum number of connections to be - * allowed to any one connection. Note that, as long as the legacy - * "disallow duplicate" and "disallow simultaneous" properties are still - * supported, these cannot be constants, as the legacy properties dictate - * the values that should be used in the absence of the correct properties. + * allowed to any one connection. */ - private int DEFAULT_MAX_CONNECTIONS = 0; + private static final int DEFAULT_MAX_CONNECTIONS = 0; /** * The default value for the default maximum number of connections to be - * allowed to any one connection group. Note that, as long as the legacy - * "disallow duplicate" and "disallow simultaneous" properties are still - * supported, these cannot be constants, as the legacy properties dictate - * the values that should be used in the absence of the correct properties. + * allowed to any one connection group. */ - private int DEFAULT_MAX_GROUP_CONNECTIONS = 0; + private static final int DEFAULT_MAX_GROUP_CONNECTIONS = 0; /** - * The value for the sqlserver-driver property that triggers the use of - * the open source JTDS driver. + * The default SQLServer driver to use. */ - 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"; + public static final SQLServerDriver SQLSERVER_DEFAULT_DRIVER = SQLServerDriver.MICROSOFT_2005; /** * Constructs a new SQLServerEnvironment, providing access to SQLServer-specific @@ -133,75 +100,6 @@ public class SQLServerEnvironment extends JDBCEnvironment { // Init underlying JDBC environment super(); - // Read legacy concurrency-related property - Boolean disallowSimultaneous = getProperty(SQLServerGuacamoleProperties.SQLSERVER_DISALLOW_SIMULTANEOUS_CONNECTIONS); - Boolean disallowDuplicate = getProperty(SQLServerGuacamoleProperties.SQLSERVER_DISALLOW_DUPLICATE_CONNECTIONS); - - // Legacy "simultaneous" property dictates only the maximum number of - // connections per connection - if (disallowSimultaneous != null) { - - // Translate legacy property - if (disallowSimultaneous) { - DEFAULT_MAX_CONNECTIONS = 1; - DEFAULT_MAX_GROUP_CONNECTIONS = 0; - } - else { - DEFAULT_MAX_CONNECTIONS = 0; - DEFAULT_MAX_GROUP_CONNECTIONS = 0; - } - - // Warn of deprecation - logger.warn("The \"{}\" property is deprecated. Use \"{}\" and \"{}\" instead.", - SQLServerGuacamoleProperties.SQLSERVER_DISALLOW_SIMULTANEOUS_CONNECTIONS.getName(), - SQLServerGuacamoleProperties.SQLSERVER_DEFAULT_MAX_CONNECTIONS.getName(), - SQLServerGuacamoleProperties.SQLSERVER_DEFAULT_MAX_GROUP_CONNECTIONS.getName()); - - // Inform of new equivalent - logger.info("To achieve the same result of setting \"{}\" to \"{}\", set \"{}\" to \"{}\" and \"{}\" to \"{}\".", - SQLServerGuacamoleProperties.SQLSERVER_DISALLOW_SIMULTANEOUS_CONNECTIONS.getName(), disallowSimultaneous, - SQLServerGuacamoleProperties.SQLSERVER_DEFAULT_MAX_CONNECTIONS.getName(), DEFAULT_MAX_CONNECTIONS, - SQLServerGuacamoleProperties.SQLSERVER_DEFAULT_MAX_GROUP_CONNECTIONS.getName(), DEFAULT_MAX_GROUP_CONNECTIONS); - - } - - // Legacy "duplicate" property dictates whether connections and groups - // may be used concurrently only by different users - if (disallowDuplicate != null) { - - // Translate legacy property - if (disallowDuplicate) { - DEFAULT_MAX_CONNECTIONS_PER_USER = 1; - DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER = 1; - } - else { - DEFAULT_MAX_CONNECTIONS_PER_USER = 0; - DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER = 0; - } - - // Warn of deprecation - logger.warn("The \"{}\" property is deprecated. Use \"{}\" and \"{}\" instead.", - SQLServerGuacamoleProperties.SQLSERVER_DISALLOW_DUPLICATE_CONNECTIONS.getName(), - SQLServerGuacamoleProperties.SQLSERVER_DEFAULT_MAX_CONNECTIONS_PER_USER.getName(), - SQLServerGuacamoleProperties.SQLSERVER_DEFAULT_MAX_GROUP_CONNECTIONS.getName()); - - // Inform of new equivalent - logger.info("To achieve the same result of setting \"{}\" to \"{}\", set \"{}\" to \"{}\" and \"{}\" to \"{}\".", - SQLServerGuacamoleProperties.SQLSERVER_DISALLOW_DUPLICATE_CONNECTIONS.getName(), disallowDuplicate, - SQLServerGuacamoleProperties.SQLSERVER_DEFAULT_MAX_CONNECTIONS_PER_USER.getName(), DEFAULT_MAX_CONNECTIONS_PER_USER, - SQLServerGuacamoleProperties.SQLSERVER_DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER.getName(), DEFAULT_MAX_GROUP_CONNECTIONS_PER_USER); - - } - - // Check driver property is one of the acceptable values. - String driver = getProperty(SQLServerGuacamoleProperties.SQLSERVER_DRIVER); - if (driver != null && !(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 @@ -337,20 +235,19 @@ public class SQLServerEnvironment extends JDBCEnvironment { } /** - * Returns whether or not to use the SourceForge JTDS driver for more - * generic JTDS connections instead of the Microsoft-provided JDBC driver. + * Returns which JDBC driver should be used to make the SQLServer/TDS connection. * * @return - * True if the JTDS driver should be used; false by default. + * Which TDS-compatible JDBC driver should be used. * * @throws GuacamoleException * If an error occurs while retrieving the property value, or if the * value was not set, as this property is required. */ - public String getSQLServerDriver() throws GuacamoleException { + public SQLServerDriver getSQLServerDriver() throws GuacamoleException { return getProperty( SQLServerGuacamoleProperties.SQLSERVER_DRIVER, - SQLSERVER_DRIVER_MS_2005 + SQLSERVER_DEFAULT_DRIVER ); } 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 9d9b3864b..8aa02b383 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 @@ -198,10 +198,10 @@ public class SQLServerGuacamoleProperties { }; /** - * Whether or not to use the JTDS driver for SQL Server connections. + * Which TDS-compatible JDBC driver should be used for the connection. */ - public static final StringGuacamoleProperty - SQLSERVER_DRIVER = new StringGuacamoleProperty() { + public static final SQLServerDriverProperty + SQLSERVER_DRIVER = new SQLServerDriverProperty() { @Override public String getName() { return "sqlserver-driver"; }