mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-363: Implement new SQLServerDriver data type and property to select the property SQL Server driver.
This commit is contained in:
@@ -42,9 +42,9 @@ public class SQLServerAuthenticationProviderModule implements Module {
|
|||||||
private final Properties driverProperties = new Properties();
|
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
|
* Creates a new SQLServer authentication provider module that configures
|
||||||
@@ -83,17 +83,26 @@ public class SQLServerAuthenticationProviderModule implements Module {
|
|||||||
@Override
|
@Override
|
||||||
public void configure(Binder binder) {
|
public void configure(Binder binder) {
|
||||||
|
|
||||||
// Bind SQLServer-specific properties
|
// Bind SQLServer-specific properties with the configured driver.
|
||||||
// Look at the property to choose the correct driver.
|
switch(sqlServerDriver) {
|
||||||
if (sqlServerDriver.equals(SQLServerEnvironment.SQLSERVER_DRIVER_JTDS))
|
case JTDS:
|
||||||
JdbcHelper.SQL_Server_jTDS.configure(binder);
|
JdbcHelper.SQL_Server_jTDS.configure(binder);
|
||||||
else if (sqlServerDriver.equals(SQLServerEnvironment.SQLSERVER_DRIVER_DATADIRECT))
|
break;
|
||||||
|
|
||||||
|
case DATA_DIRECT:
|
||||||
JdbcHelper.SQL_Server_DataDirect.configure(binder);
|
JdbcHelper.SQL_Server_DataDirect.configure(binder);
|
||||||
else if (sqlServerDriver.equals(SQLServerEnvironment.SQLSERVER_DRIVER_MS))
|
break;
|
||||||
|
|
||||||
|
case MICROSOFT_LEGACY:
|
||||||
JdbcHelper.SQL_Server_MS_Driver.configure(binder);
|
JdbcHelper.SQL_Server_MS_Driver.configure(binder);
|
||||||
else
|
break;
|
||||||
|
|
||||||
|
case MICROSOFT_2005:
|
||||||
|
default:
|
||||||
JdbcHelper.SQL_Server_2005_MS_Driver.configure(binder);
|
JdbcHelper.SQL_Server_2005_MS_Driver.configure(binder);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Bind MyBatis properties
|
// Bind MyBatis properties
|
||||||
Names.bindProperties(binder, myBatisProperties);
|
Names.bindProperties(binder, myBatisProperties);
|
||||||
|
|
||||||
|
@@ -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;
|
||||||
|
}
|
@@ -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<SQLServerDriver> {
|
||||||
|
|
||||||
|
@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\".");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -56,69 +56,36 @@ public class SQLServerEnvironment extends JDBCEnvironment {
|
|||||||
* The default value for the maximum number of connections to be
|
* The default value for the maximum number of connections to be
|
||||||
* allowed to the Guacamole server overall.
|
* 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
|
* 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
|
* allowed per user to any one connection.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
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
|
* 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
|
* allowed per user to any one connection group.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
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
|
* The default value for the default maximum number of connections to be
|
||||||
* allowed to any one connection. Note that, as long as the legacy
|
* allowed to any one connection.
|
||||||
* "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.
|
|
||||||
*/
|
*/
|
||||||
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
|
* 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
|
* allowed to any one connection group.
|
||||||
* "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.
|
|
||||||
*/
|
*/
|
||||||
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 default SQLServer driver to use.
|
||||||
* the open source JTDS driver.
|
|
||||||
*/
|
*/
|
||||||
public final static String SQLSERVER_DRIVER_JTDS = "jtds";
|
public static final SQLServerDriver SQLSERVER_DEFAULT_DRIVER = SQLServerDriver.MICROSOFT_2005;
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
||||||
@@ -133,75 +100,6 @@ public class SQLServerEnvironment extends JDBCEnvironment {
|
|||||||
// Init underlying JDBC environment
|
// Init underlying JDBC environment
|
||||||
super();
|
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
|
@Override
|
||||||
@@ -337,20 +235,19 @@ public class SQLServerEnvironment extends JDBCEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not to use the SourceForge JTDS driver for more
|
* Returns which JDBC driver should be used to make the SQLServer/TDS connection.
|
||||||
* generic JTDS connections instead of the Microsoft-provided JDBC driver.
|
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* True if the JTDS driver should be used; false by default.
|
* Which TDS-compatible JDBC driver should be used.
|
||||||
*
|
*
|
||||||
* @throws GuacamoleException
|
* @throws GuacamoleException
|
||||||
* 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 String getSQLServerDriver() throws GuacamoleException {
|
public SQLServerDriver getSQLServerDriver() throws GuacamoleException {
|
||||||
return getProperty(
|
return getProperty(
|
||||||
SQLServerGuacamoleProperties.SQLSERVER_DRIVER,
|
SQLServerGuacamoleProperties.SQLSERVER_DRIVER,
|
||||||
SQLSERVER_DRIVER_MS_2005
|
SQLSERVER_DEFAULT_DRIVER
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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
|
public static final SQLServerDriverProperty
|
||||||
SQLSERVER_DRIVER = new StringGuacamoleProperty() {
|
SQLSERVER_DRIVER = new SQLServerDriverProperty() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() { return "sqlserver-driver"; }
|
public String getName() { return "sqlserver-driver"; }
|
||||||
|
Reference in New Issue
Block a user